.gitinogre: update the command to check tracked files being ignored
PATCH 1/2 .gitinogre: update the command to check tracked files being ignored
Recent git versions do not accept the noted command.
$ git ls-files -i --exclude-standard fatal: ls-files -i must be used with either -o or -c
The -c was implied for older git versions, but we need to make it explicit now.
Also, replace --exclude-standard with --exclude-per-directory=.gitignore so that everyone will get consistent results.
git-ls-files(1) says:
--exclude-standard
Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.
We never know what are locally added to $GIT_DIR/info/exclude or $XDG_CONFIG_HOME/git/ignore.
We can only manage .gitignore files committed in the repository.
---
.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.gitignore +1 -1
@@ -4,7 +4,7 @@ # subdirectories here. Add them in the ".gitignore" file # in that subdirectory instead. # -# NOTE! Please use 'git ls-files -i --exclude-standard' +# NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore' # command after changing this file, to see if there are # any tracked files which get ignored after the change. #
Signature · 1 line
2.34.1
PATCH 2/2 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 the v6.1 kernel 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.).
---
Makefile | 6 ++++++ scripts/misc-check | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 scripts/misc-check
Makefile +6 -0
@@ -1852,6 +1852,12 @@ rust-analyzer: # Misc # --------------------------------------------------------------------------- +PHONY += misc-check +misc-check: + $(Q)scripts/misc-check + +all: misc-check + PHONY += scripts_gdb scripts_gdb: prepare0 $(Q)$(MAKE) $(build)=scripts/gdb
scripts/misc-check new file +19 -0
@@ -0,0 +1,19 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +set -e + +# Detect files that are tracked but ignored by git. This is checked only when +# ${KBUILD_EXTRA_WARN} contains 1, git is installed, and the source tree is +# tracked by git. +check_tracked_ignored_files () { + case "${KBUILD_EXTRA_WARN}" in + *1*) ;; + *) return;; + esac + + git ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | + sed 's/$/: warning: ignored by one of the .gitignore files/' >&2 +} + +check_tracked_ignored_files
Signature · 1 line
2.34.1