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

git diff-index with relative git-dir does not work

From
Yasushi SHOJI <yashi@atmark-techno.com>
Date
Feb 9, 2010, 11:05 UTC
Message-ID
<871vguy8hz.wl@dns1.atmark-techno.com>
Hi all,

I was just testing --git-dir and --work-tree options and found that the following test code fails with the current next (2ac040d3).

	diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
	index 9df3012..1f90f45 100755
	--- a/t/t1501-worktree.sh
	+++ b/t/t1501-worktree.sh
	@@ -195,4 +195,8 @@ test_expect_success 'make_relative_path handles double slashes in GIT_DIR' '
	 	git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file
	 '
	 
	+test_expect_success 'git diff-index' '
	+	git --git-dir repo.git --work-tree repo.git/work diff-index HEAD
	+'
	+
	 test_done

This is because static variable 'base' in sha1_file_name is already assigned _before_ setup_work_tree() from cmd_diff_index() is called. setup_work_tree() eventually chdir to the given work tree dir, but we use the old base to generate object file path. And that cause open(2) to fail because the object file path and the current dir is not in sync any more.

So, is it correct to assume that we must call setup_work_tree() _before_ any function which call getter/setter in environment.c? This including open_sha1_file, in this case.

Also, would it be a good idea to make all builtin command to _explicitly_ call setup_* functions, so that we can find calling order bug? In that case, we must change the setup functions signature to allow marking "not interested" or something.

Any thoughts?
-- 
           yashi
Next: Nguyen Thai Ngoc Duy
Message 1 of 4 in “git diff-index with relative git-dir does not work”
  1. Yasushi SHOJIFeb 9, 2010
  2. Nguyen Thai Ngoc DuyFeb 9, 2010
  3. Yasushi SHOJIFeb 9, 2010
  4. Nguyen Thai Ngoc DuyFeb 11, 2010

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.