git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/8] t7900: do not let `$HOME/.gitconfig` interfere with XDG tests

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 26, 2026, 14:38 UTC
Message-ID
<4dc5151e59f289da2195f88c1f8bddfdf71343c6.1777214316.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2098.v2.git.1777214316.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 t/t7900-maintenance.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 4700beacc1..4358df0424 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -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 &&
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 13 of 19 in “safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGES”
  1. 0/8 safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGESJohannes Schindelin via GitGitGadget, Apr 24, 2026
  2. 1/8 test-lib: allow bare repository access when breaking changes are enabledJohannes Schindelin via GitGitGadget, Apr 24, 2026
  3. 2/8 t7900: do not let `$HOME/.gitconfig` interfere with XDG testsJohannes Schindelin via GitGitGadget, Apr 24, 2026
  4. 3/8 t1300: remove global config settings injected by test-lib.shJohannes Schindelin via GitGitGadget, Apr 24, 2026
  5. 6/8 ls-files tests: filter `.gitconfig` from `--others` outputJohannes Schindelin via GitGitGadget, Apr 24, 2026
  6. Junio C HamanoApr 26, 2026
  7. 7/8 status tests: filter `.gitconfig` from status outputJohannes Schindelin via GitGitGadget, Apr 24, 2026
  8. 8/8 safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGESJohannes Schindelin via GitGitGadget, Apr 24, 2026
  9. 4/8 t1305: use `--git-dir=.` for bare repo in include cycle testJohannes Schindelin via GitGitGadget, Apr 24, 2026
  10. 5/8 t5601: restore `.gitconfig` after includeIf testJohannes Schindelin via GitGitGadget, Apr 24, 2026
  11. 0/8 safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGESJohannes Schindelin via GitGitGadget, Apr 26, 2026
  12. 1/8 test-lib: allow bare repository access when breaking changes are enabledJohannes Schindelin via GitGitGadget, Apr 26, 2026
  13. 2/8 t7900: do not let `$HOME/.gitconfig` interfere with XDG testsJohannes Schindelin via GitGitGadget, Apr 26, 2026
  14. 3/8 t1300: remove global config settings injected by test-lib.shJohannes Schindelin via GitGitGadget, Apr 26, 2026
  15. 4/8 t1305: use `--git-dir=.` for bare repo in include cycle testJohannes Schindelin via GitGitGadget, Apr 26, 2026
  16. 5/8 t5601: restore `.gitconfig` after includeIf testJohannes Schindelin via GitGitGadget, Apr 26, 2026
  17. 6/8 ls-files tests: filter `.gitconfig` from `--others` outputJohannes Schindelin via GitGitGadget, Apr 26, 2026
  18. 7/8 status tests: filter `.gitconfig` from status outputJohannes Schindelin via GitGitGadget, Apr 26, 2026
  19. 8/8 safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGESJohannes Schindelin via GitGitGadget, Apr 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.