t7900: do not let `$HOME/.gitconfig` interfere with XDG tests

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>

Johannes Schindelin committed Apr 26, 2026 at 14:38 UTC a27fec3e7eb13a0941e75cd16a31e424c276b334
1 file changed +10 -2
t/t7900-maintenance.sh
+10 -2
@@ -101,8 +101,12 @@ test_expect_success "maintenance.autoDetach overrides gc.autoDetach" '
101 test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
102 test_when_finished rm -r .config/git/config &&
103 (
104 + # Override HOME so that .gitconfig (which test-lib.sh may
105 + # have created, e.g. to set safe.bareRepository) does not
106 + # take precedence over the XDG location.
107 + HOME=$PWD/must-not-exist &&
108 XDG_CONFIG_HOME=.config &&
105 - export XDG_CONFIG_HOME &&
109 + export HOME XDG_CONFIG_HOME &&
110 mkdir -p $XDG_CONFIG_HOME/git &&
111 >$XDG_CONFIG_HOME/git/config &&
112 git maintenance register &&
@@ -124,8 +128,12 @@ test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' '
128 test_expect_success 'unregister uses XDG_CONFIG_HOME config if it exists' '
129 test_when_finished rm -r .config/git/config &&
130 (
131 + # Override HOME so that .gitconfig (which test-lib.sh may
132 + # have created, e.g. to set safe.bareRepository) does not
133 + # take precedence over the XDG location.
134 + HOME=$PWD/must-not-exist &&
135 XDG_CONFIG_HOME=.config &&
128 - export XDG_CONFIG_HOME &&
136 + export HOME XDG_CONFIG_HOME &&
137 mkdir -p $XDG_CONFIG_HOME/git &&
138 >$XDG_CONFIG_HOME/git/config &&
139 git maintenance register &&