ls-files tests: filter .gitconfig from --others output

The global `safe.bareRepository=all` setting in test-lib.sh is
written to `$HOME/.gitconfig`, which unfortunately lives inside the
test repository's working tree. The `.git/info/exclude` entry added
alongside it handles most commands, but `git ls-files --others`
without `--exclude-standard` does not consult `info/exclude` at
all, so the file appears in the output.

Ideally, each test that accesses a bare repository would simply
specify `--git-dir` or `GIT_DIR` explicitly, which would require no
global config and produce no side effects in the working tree. As
that approach was not taken, filter `.gitconfig` from the output
before comparing against expected results. In t7104, the test
already uses `--exclude-standard`, so it suffices to switch from
the bare `git ls-files -o` to `git ls-files -o --exclude-standard`
which respects the `info/exclude` entry; the other tests
deliberately omit `--exclude-standard` because their purpose is to
verify unfiltered `--others` output.

Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2026-04-26 14:38:34 +00:00
committed by Junio C Hamano
parent d97f27bf01
commit 83228f1661
7 changed files with 21 additions and 2 deletions
+4
View File
@@ -53,16 +53,19 @@ test_expect_success 'setup: expected output' '
test_expect_success 'ls-files --others' '
git ls-files --others >output &&
test_filter_gitconfig output &&
test_cmp expected1 output
'
test_expect_success 'ls-files --others --directory' '
git ls-files --others --directory >output &&
test_filter_gitconfig output &&
test_cmp expected2 output
'
test_expect_success '--no-empty-directory hides empty directory' '
git ls-files --others --directory --no-empty-directory >output &&
test_filter_gitconfig output &&
test_cmp expected3 output
'
@@ -70,6 +73,7 @@ test_expect_success 'ls-files --others handles non-submodule .git' '
mkdir not-a-submodule &&
echo foo >not-a-submodule/.git &&
git ls-files -o >output &&
test_filter_gitconfig output &&
test_cmp expected1 output
'
+3
View File
@@ -72,6 +72,7 @@ test_expect_success 'git ls-files --others with various exclude options.' '
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
>output &&
test_filter_gitconfig output &&
test_cmp expect output
'
@@ -84,6 +85,7 @@ test_expect_success 'git ls-files --others with \r\n line endings.' '
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
>output &&
test_filter_gitconfig output &&
test_cmp expect output
'
@@ -99,6 +101,7 @@ test_expect_success 'git ls-files --others with various exclude options.' '
--exclude-per-directory=.gitignore \
--exclude-from=.git/ignore \
>output &&
test_filter_gitconfig output &&
test_cmp expect output
'
+2
View File
@@ -24,6 +24,7 @@ test_expect_success 'setup' '
test_expect_success 'git ls-files without path restriction.' '
test_when_finished "rm -f expect" &&
git ls-files --others >output &&
test_filter_gitconfig output &&
cat >expect <<-\EOF &&
--
-foo
@@ -63,6 +64,7 @@ test_expect_success 'git ls-files with path restriction with -- --.' '
test_expect_success 'git ls-files with no path restriction.' '
test_when_finished "rm -f expect" &&
git ls-files --others -- >output &&
test_filter_gitconfig output &&
cat >expect <<-\EOF &&
--
-foo
+1
View File
@@ -36,6 +36,7 @@ test_expect_success 'setup: directories' '
test_expect_success 'ls-files --others handles untracked git repositories' '
git ls-files -o >output &&
test_filter_gitconfig output &&
cat >expect <<-EOF &&
nonrepo-untracked-file/untracked
output
@@ -26,7 +26,7 @@ test_expect_success 'setup' '
'
test_expect_success 'git ls-files -o shows the right entries' '
cat <<-EOF >expect &&
cat >expect <<-EOF &&
.gitignore
actual
an_ignored_dir/ignored
@@ -39,6 +39,7 @@ test_expect_success 'git ls-files -o shows the right entries' '
untracked_repo/
EOF
git ls-files -o >actual &&
test_filter_gitconfig actual &&
test_cmp expect actual
'
+1 -1
View File
@@ -21,7 +21,7 @@ test_expect_success setup '
rm -f hello &&
mkdir -p hello &&
>hello/world &&
test "$(git ls-files -o)" = hello/world
test "$(git ls-files -o --exclude-standard)" = hello/world
'
+8
View File
@@ -2069,3 +2069,11 @@ test_trailing_hash () {
test_redact_non_printables () {
tr -d "\n\r" | tr "[\001-\040][\177-\377]" "."
}
# Remove .gitconfig entries from a file in place. test-lib.sh may
# create $HOME/.gitconfig (e.g. to set safe.bareRepository) which
# can appear in ls-files or status output.
test_filter_gitconfig () {
sed "/\\.gitconfig/d" "$1" >"$1.filtered" &&
mv "$1.filtered" "$1"
}