]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t7900: do not let `$HOME/.gitconfig` interfere with XDG tests
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sun, 26 Apr 2026 14:38:30 +0000 (14:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Apr 2026 05:50:53 +0000 (14:50 +0900)
The XDG config tests for `git maintenance register/unregister`
create a fresh `$XDG_CONFIG_HOME/git/config` and expect git to use
that location. However, if `$HOME/.gitconfig` exists (which may
happen when test-lib.sh writes global config, e.g. to set
`safe.bareRepository`), git prefers `$HOME/.gitconfig` over the XDG
location, and the `maintenance.repo` entry ends up in the wrong
file.

This is an inherent consequence of setting global config in
test-lib.sh rather than adjusting individual tests: writing any
entry to `$HOME/.gitconfig` has side effects beyond the intended
setting, because the mere existence of that file changes which
global config location git prefers for all subsequent writes.
Individual per-test adjustments would not have this interaction.

Fix this by overriding `HOME` to a non-existent directory inside the
subshells that test XDG behavior. Since these subshells already
override `XDG_CONFIG_HOME`, they do not need `$HOME/.gitconfig` at
all, and the subshell scoping ensures the original `HOME` is
restored automatically.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7900-maintenance.sh

index 4700beacc18281413fc8d88ff35ea6ce392b0208..4358df04245a9a6b5458dd5d51d8b3aa92ac5e46 100755 (executable)
@@ -101,8 +101,12 @@ test_expect_success "maintenance.autoDetach overrides gc.autoDetach" '
 test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
        test_when_finished rm -r .config/git/config &&
        (
+               # Override HOME so that .gitconfig (which test-lib.sh may
+               # have created, e.g. to set safe.bareRepository) does not
+               # take precedence over the XDG location.
+               HOME=$PWD/must-not-exist &&
                XDG_CONFIG_HOME=.config &&
-               export XDG_CONFIG_HOME &&
+               export HOME XDG_CONFIG_HOME &&
                mkdir -p $XDG_CONFIG_HOME/git &&
                >$XDG_CONFIG_HOME/git/config &&
                git maintenance register &&
@@ -124,8 +128,12 @@ test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' '
 test_expect_success 'unregister uses XDG_CONFIG_HOME config if it exists' '
        test_when_finished rm -r .config/git/config &&
        (
+               # Override HOME so that .gitconfig (which test-lib.sh may
+               # have created, e.g. to set safe.bareRepository) does not
+               # take precedence over the XDG location.
+               HOME=$PWD/must-not-exist &&
                XDG_CONFIG_HOME=.config &&
-               export XDG_CONFIG_HOME &&
+               export HOME XDG_CONFIG_HOME &&
                mkdir -p $XDG_CONFIG_HOME/git &&
                >$XDG_CONFIG_HOME/git/config &&
                git maintenance register &&