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

[PATCH 3/3] t5403: do not use access repos with GIT_DIR when worktree is involved

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 12, 2011, 09:35 UTC
Message-ID
<1318412105-13595-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1318412105-13595-1-git-send-email-pclouds@gmail.com>

Setting GIT_DIR alone means worktree is current directory for legacy reasons. Avoid using that, instead go to the worktree and execute commands there.

The troublesome command is "GIT_DIR=clone2/.git git add clone2/b". The real worktree is clone2, but that command tells git worktree is $(pwd). What does user expect to add then? Should the new entry in index be "b" or "clone2/b"?

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 t/t5403-post-checkout-hook.sh |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh
index 6643f32..3459539 100755
--- a/t/t5403-post-checkout-hook.sh
+++ b/t/t5403-post-checkout-hook.sh
@@ -13,10 +13,13 @@ test_expect_success setup '
 	git commit -m setup &&
 	git clone ./. clone1 &&
 	git clone ./. clone2 &&
-	GIT_DIR=clone2/.git git branch new2 &&
-	echo Data for commit1. >clone2/b &&
-	GIT_DIR=clone2/.git git add clone2/b &&
-	GIT_DIR=clone2/.git git commit -m new2
+	(
+		cd clone2 &&
+		git branch new2 &&
+		echo Data for commit1. >b &&
+		git add b &&
+		git commit -m new2
+	)
 '
 
 for clone in 1 2; do
@@ -45,7 +48,7 @@ test_expect_success 'post-checkout runs as expected ' '
 '
 
 test_expect_success 'post-checkout args are correct with git checkout -b ' '
-	GIT_DIR=clone1/.git git checkout -b new1 &&
+	( cd clone1 && git checkout -b new1 ) &&
 	old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
 	new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
 	flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
@@ -53,7 +56,7 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' '
 '
 
 test_expect_success 'post-checkout receives the right args with HEAD changed ' '
-	GIT_DIR=clone2/.git git checkout new2 &&
+	( cd clone2 && git checkout new2 ) &&
 	old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
 	new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
 	flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
@@ -61,7 +64,7 @@ test_expect_success 'post-checkout receives the right args with HEAD changed ' '
 '
 
 test_expect_success 'post-checkout receives the right args when not switching branches ' '
-	GIT_DIR=clone2/.git git checkout master b &&
+	( cd clone2 && git checkout master b ) &&
 	old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
 	new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
 	flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
-- 
1.7.3.1.256.g2539c.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 3 of 7 in “t5403.1: simplify commit creation”
  1. 1/3 t5403.1: simplify commit creationNguyễn Thái Ngọc Duy, Oct 12, 2011
  2. 2/3 t5403: convert leading spaces to tabsNguyễn Thái Ngọc Duy, Oct 12, 2011
  3. 3/3 t5403: do not use access repos with GIT_DIR when worktree is involvedNguyễn Thái Ngọc Duy, Oct 12, 2011
  4. Junio C HamanoOct 13, 2011
  5. Nguyen Thai Ngoc DuyOct 13, 2011
  6. Johannes SixtOct 12, 2011
  7. Nguyen Thai Ngoc DuyOct 13, 2011

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.