]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-files tests: filter `.gitconfig` from `--others` output
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sun, 26 Apr 2026 14:38:34 +0000 (14:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Apr 2026 05:50:53 +0000 (14:50 +0900)
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>
t/t3000-ls-files-others.sh
t/t3001-ls-files-others-exclude.sh
t/t3002-ls-files-dashpath.sh
t/t3009-ls-files-others-nonsubmodule.sh
t/t3011-common-prefixes-and-directory-traversal.sh
t/t7104-reset-hard.sh
t/test-lib-functions.sh

index b41e7f0daa480dd0cad786166de77d4dfbd307fc..b4f0fbfc55a0fe625d9470ae08fe51bd7286ac98 100755 (executable)
@@ -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
 '
 
index 4b676462852ab8436e1c72eb4ca759cfea2b8d34..202fb8d9eacc2cb54c8257f8f2c90879b03debe5 100755 (executable)
@@ -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
 '
 
index 31462cb441ef2fc4e2bab6e12a4e1aca9425ef4d..6acaadbd672cdec41181a5682599f95446a884e1 100755 (executable)
@@ -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
index 963f3462b750b2a4fc7d009df6cf1fa1949090d6..dc990c277bcaa8eba75efda4b36f969123890c17 100755 (executable)
@@ -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
index 3da5b2b6e795ec4587608ead8bc10abf0c6d9039..455e97954d7721766376a5a286a20cd012700eb2 100755 (executable)
@@ -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
 '
 
index 7948ec392b3599a3884d97ae21f5deece84e638c..c23d6e3f526c855ec9c9d8e8862398f6a2c3af98 100755 (executable)
@@ -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
 
 '
 
index f3af10fb7e020500f10336c4a7b7e698b9d135e4..0505da78e83527862cccaeb61ca4541b93b5dee3 100644 (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"
+}