Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: make W=1 warn files that are tracked but ignored by git

The top .gitignore comments about how to detect files breaking
.gitignore rules, but people rarely care about it.

Add a new W=1 warning to detect files that are tracked but ignored by
git. If git is not installed or the source tree is not tracked by git
at all, this script does not print anything.

Running it on v6.2-rc1 detected the following:

$ make W=1 misc-check
Documentation/devicetree/bindings/.yamllint: warning: ignored by one of the .gitignore files
drivers/clk/.kunitconfig: warning: ignored by one of the .gitignore files
drivers/gpu/drm/tests/.kunitconfig: warning: ignored by one of the .gitignore files
drivers/hid/.kunitconfig: warning: ignored by one of the .gitignore files
fs/ext4/.kunitconfig: warning: ignored by one of the .gitignore files
fs/fat/.kunitconfig: warning: ignored by one of the .gitignore files
kernel/kcsan/.kunitconfig: warning: ignored by one of the .gitignore files
lib/kunit/.kunitconfig: warning: ignored by one of the .gitignore files
mm/kfence/.kunitconfig: warning: ignored by one of the .gitignore files
tools/testing/selftests/arm64/tags/.gitignore: warning: ignored by one of the .gitignore files
tools/testing/selftests/arm64/tags/Makefile: warning: ignored by one of the .gitignore files
tools/testing/selftests/arm64/tags/run_tags_test.sh: warning: ignored by one of the .gitignore files
tools/testing/selftests/arm64/tags/tags_test.c: warning: ignored by one of the .gitignore files

These are ignored by the '.*' or 'tags' in the top .gitignore, but
there is no rule to negate it.

You might be tempted to do 'git add -f' but I want to have the real
issue fixed (by fixing a .gitignore, or by renaming files, etc.).

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

+25
+6
Makefile
··· 1861 1861 # Misc 1862 1862 # --------------------------------------------------------------------------- 1863 1863 1864 + PHONY += misc-check 1865 + misc-check: 1866 + $(Q)$(srctree)/scripts/misc-check 1867 + 1868 + all: misc-check 1869 + 1864 1870 PHONY += scripts_gdb 1865 1871 scripts_gdb: prepare0 1866 1872 $(Q)$(MAKE) $(build)=scripts/gdb
+19
scripts/misc-check
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + set -e 5 + 6 + # Detect files that are tracked but ignored by git. This is checked only when 7 + # ${KBUILD_EXTRA_WARN} contains 1, git is installed, and the source tree is 8 + # tracked by git. 9 + check_tracked_ignored_files () { 10 + case "${KBUILD_EXTRA_WARN}" in 11 + *1*) ;; 12 + *) return;; 13 + esac 14 + 15 + git -C ${srctree:-.} ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | 16 + sed 's/$/: warning: ignored by one of the .gitignore files/' >&2 17 + } 18 + 19 + check_tracked_ignored_files