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

[PATCH git] t5516: test updateInstead with worktree and unborn bare HEAD

From
Runxi Yu <me@runxiyu.org>
Date
Feb 23, 2026, 14:12 UTC
Message-ID
<20260223141236.22476-1-me@runxiyu.org>

This is a regression test which should presently fail, to demonstrate the behavior I encountered that looks like a bug.

When a bare repository has a worktree checked out on a separate branch, receive.denyCurrentBranch=updateInstead should allow a push to that branch and update the linked worktree, as long as the linked worktree is clean.

But, if the bare repository's own HEAD is repointed to an unborn branch, the push is rejected with "Working directory has staged changes", even though the linked worktree itself is clean.

This test is essentially a minimal working example of what I encountered while actually using Git; it might not be the optimal way to demonstrate the underlying bug. I suspect builtin/receive-pack.c is using the bare repository's HEAD even when comparing it to the worktree's index.

Signed-off-by: Runxi Yu <me@runxiyu.org>
---
 t/t5516-fetch-push.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 29e2f17608..f44250c38f 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1816,6 +1816,24 @@ test_expect_success 'denyCurrentBranch and bare repository worktrees' '
 	test_must_fail git push --delete bare.git wt
 '
 
+# NEEDSWORK: updateInstead unexpectedly fails when bare HEAD points to unborn
+# branch (or probably any ref that differs from the target worktree) despite
+# the target worktree being clean. This seems to be because receive-pack.c
+# diffs the target worktree index against the bare repository HEAD.
+test_expect_failure 'updateInstead with bare repository worktree and unborn bare HEAD' '
+	test_when_finished "rm -fr bare.git cloned" &&
+	git clone --bare . bare.git &&
+	git -C bare.git worktree add wt &&
+	git -C bare.git config receive.denyCurrentBranch updateInstead &&
+	git -C bare.git symbolic-ref HEAD refs/heads/unborn &&
+	test_must_fail git -C bare.git rev-parse -q --verify HEAD^{commit} &&
+	git clone . cloned &&
+	test_commit -C cloned mozzarella &&
+	git -C cloned push ../bare.git HEAD:wt &&
+	test_path_exists bare.git/wt/mozzarella.t &&
+	test "$(git -C cloned rev-parse HEAD)" = "$(git -C bare.git/wt rev-parse HEAD)"
+'
+
 test_expect_success 'refuse fetch to current branch of worktree' '
 	test_when_finished "git worktree remove --force wt && git branch -D wt" &&
 	git worktree add wt &&
-- 
2.53.0
Next: Junio C Hamano
Message 1 of 11 in “t5516: test updateInstead with worktree and unborn bare HEAD”
  1. t5516: test updateInstead with worktree and unborn bare HEADRunxi Yu, Feb 23, 2026
  2. Junio C HamanoFeb 23, 2026
  3. Runxi YuFeb 24, 2026
  4. Runxi YuMar 3, 2026
  5. 0/3 receive-pack: fix HEAD check for updateInsteadPablo Sabater, Mar 30, 2026
  6. 1/3 t5516: test updateInstead with worktree and unborn bare HEADPablo Sabater, Mar 30, 2026
  7. 2/3 t5516: clean up cloned and new-wt in denyCurrentBranch and worktrees testPablo Sabater, Mar 30, 2026
  8. 3/3 receive-pack: use worktree HEAD for updateInsteadPablo Sabater, Mar 30, 2026
  9. Junio C HamanoMar 30, 2026
  10. PabloMar 30, 2026
  11. Junio C HamanoMar 31, 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.