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

[PATCH v4 5/6] t7006: demonstrate a problem with aliases in subdirectories

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 14, 2017, 11:35 UTC
Message-ID
<ba1ae3d6cc5c1722d00480267cfa9b4946c0c0ea.1497440104.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1497440104.git.johannes.schindelin@gmx.de>

When expanding aliases, the git_dir is set during the alias expansion (by virtue of running setup_git_directory_gently()).

This git_dir may be relative to the current working directory, and indeed often is simply ".git/".

When the alias expands to a shell command, we restore the original working directory, though, yet we do not reset git_dir.

As a consequence, subsequent read_early_config() runs will mistake the git_dir to be populated properly and not find the correct config.

Demonstrate this problem by adding a test case.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t7006-pager.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 4f3794d415e..83881ec3a0c 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -391,6 +391,17 @@ test_expect_success TTY 'core.pager in repo config works and retains cwd' '
 	)
 '
 
+test_expect_failure TTY 'core.pager is found via alias in subdirectory' '
+	sane_unset GIT_PAGER &&
+	test_config core.pager "cat >via-alias" &&
+	(
+		cd sub &&
+		rm -f via-alias &&
+		test_terminal git -c alias.r="-p rev-parse" r HEAD &&
+		test_path_is_file via-alias
+	)
+'
+
 test_doesnt_paginate      expect_failure test_must_fail 'git -p nonsense'
 
 test_pager_choices                       'git shortlog'
-- 
2.13.1.windows.1.1.ga36e14b3aaa
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 6 of 10 in “Avoid problem where git_dir is set after alias expansion”
  1. 0/6 Avoid problem where git_dir is set after alias expansionJohannes Schindelin, Jun 14, 2017
  2. 1/6 discover_git_directory(): avoid setting invalid git_dirJohannes Schindelin, Jun 14, 2017
  3. 3/6 help: use early config when autocorrecting aliasesJohannes Schindelin, Jun 14, 2017
  4. 4/6 t1308: relax the test verifying that empty alias values are disallowedJohannes Schindelin, Jun 14, 2017
  5. 2/6 config: report correct line number upon errorJohannes Schindelin, Jun 14, 2017
  6. 5/6 t7006: demonstrate a problem with aliases in subdirectoriesJohannes Schindelin, Jun 14, 2017
  7. 6/6 Use the early config machinery to expand aliasesJohannes Schindelin, Jun 14, 2017
  8. Junio C HamanoJun 15, 2017
  9. Johannes SchindelinJun 15, 2017
  10. Jeff KingJun 15, 2017

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.