Git development
 help / color / mirror / Atom feed
From: Pablo Sabater <pabloosabaterr@gmail.com>
To: git@vger.kernel.org
Cc: me@runxiyu.org, gitster@pobox.com, christian.couder@gmail.com,
	karthik.188@gmail.com, jltobler@gmail.com,
	ayu.chandekar@gmail.com, siddharthasthana31@gmail.com,
	chandrapratap3519@gmail.com
Subject: [GSoC PATCH 1/3] t5516: test updateInstead with worktree and unborn bare HEAD
Date: Mon, 30 Mar 2026 13:18:20 +0200	[thread overview]
Message-ID: <20260330111822.165188-2-pabloosabaterr@gmail.com> (raw)
In-Reply-To: <20260330111822.165188-1-pabloosabaterr@gmail.com>

From: Runxi Yu <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.43.0


  reply	other threads:[~2026-03-30 11:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 14:12 [PATCH git] t5516: test updateInstead with worktree and unborn bare HEAD Runxi Yu
2026-02-23 19:15 ` Junio C Hamano
2026-02-24  4:33   ` Runxi Yu
2026-03-03 10:03     ` Runxi Yu
2026-03-30 11:18 ` [GSoC PATCH 0/3] receive-pack: fix HEAD check for updateInstead Pablo Sabater
2026-03-30 11:18   ` Pablo Sabater [this message]
2026-03-30 11:18   ` [GSoC PATCH 2/3] t5516: clean up cloned and new-wt in denyCurrentBranch and worktrees test Pablo Sabater
2026-03-30 11:18   ` [GSoC PATCH 3/3] receive-pack: use worktree HEAD for updateInstead Pablo Sabater
2026-03-30 15:26   ` [GSoC PATCH 0/3] receive-pack: fix HEAD check " Junio C Hamano
2026-03-30 18:49     ` Pablo
2026-03-31 22:21   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260330111822.165188-2-pabloosabaterr@gmail.com \
    --to=pabloosabaterr@gmail.com \
    --cc=ayu.chandekar@gmail.com \
    --cc=chandrapratap3519@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=karthik.188@gmail.com \
    --cc=me@runxiyu.org \
    --cc=siddharthasthana31@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox