Add a small script that extracts all F: entries from the MAINTAINERS file
and verifies that each one matches an existing file or directory. Entries
are expanded as globs to match MAINTAINERS wildcard usage. The script
errors out and exits non-zero when a reference points to a non-existing
path, making it easy to catch stale entries.

Signed-off-by: Michal Simek <[email protected]>
---

 scripts/check_maintainers_files.sh | 47 ++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 scripts/check_maintainers_files.sh

diff --git a/scripts/check_maintainers_files.sh 
b/scripts/check_maintainers_files.sh
new file mode 100755
index 000000000000..4c1279958e98
--- /dev/null
+++ b/scripts/check_maintainers_files.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check that every "F:" file reference in MAINTAINERS exists.
+#
+# Each F: entry is treated as a shell glob (relative to the repo root),
+# matching the way MAINTAINERS wildcards work. If a pattern matches no
+# existing file or directory, it is reported and the script exits non-zero.
+
+set -u
+
+MAINTAINERS="${1:-MAINTAINERS}"
+
+if [ ! -f "$MAINTAINERS" ]; then
+       echo "error: cannot find $MAINTAINERS" >&2
+       exit 2
+fi
+
+rc=0
+
+while IFS= read -r pattern; do
+       # Strip the "F:" prefix and surrounding whitespace.
+       pattern=$(printf '%s\n' "$pattern" | sed -e 's/^F:[[:space:]]*//' -e 
's/[[:space:]]*$//')
+       [ -n "$pattern" ] || continue
+
+       # Expand the pattern as a glob; if nothing matches the glob stays 
literal.
+       matched=0
+       for path in $pattern; do
+               if [ -e "$path" ]; then
+                       matched=1
+                       break
+               fi
+       done
+
+       if [ "$matched" -eq 0 ]; then
+               echo "error: MAINTAINERS references non-existing file: 
$pattern" >&2
+               rc=1
+       fi
+done <<EOF
+$(grep '^F:' "$MAINTAINERS")
+EOF
+
+if [ "$rc" -eq 0 ]; then
+       echo "All MAINTAINERS F: entries exist."
+fi
+
+exit $rc
-- 
2.43.0

Reply via email to