Skip to content

Commit 80871f3

Browse files
runxiyugitster
authored andcommitted
t5516: test updateInstead with worktree and unborn bare HEAD
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5361983 commit 80871f3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

t/t5516-fetch-push.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,24 @@ test_expect_success 'denyCurrentBranch and bare repository worktrees' '
18161816
test_must_fail git push --delete bare.git wt
18171817
'
18181818

1819+
# NEEDSWORK: updateInstead unexpectedly fails when bare HEAD points to unborn
1820+
# branch (or probably any ref that differs from the target worktree) despite
1821+
# the target worktree being clean. This seems to be because receive-pack.c
1822+
# diffs the target worktree index against the bare repository HEAD.
1823+
test_expect_failure 'updateInstead with bare repository worktree and unborn bare HEAD' '
1824+
test_when_finished "rm -fr bare.git cloned" &&
1825+
git clone --bare . bare.git &&
1826+
git -C bare.git worktree add wt &&
1827+
git -C bare.git config receive.denyCurrentBranch updateInstead &&
1828+
git -C bare.git symbolic-ref HEAD refs/heads/unborn &&
1829+
test_must_fail git -C bare.git rev-parse -q --verify HEAD^{commit} &&
1830+
git clone . cloned &&
1831+
test_commit -C cloned mozzarella &&
1832+
git -C cloned push ../bare.git HEAD:wt &&
1833+
test_path_exists bare.git/wt/mozzarella.t &&
1834+
test "$(git -C cloned rev-parse HEAD)" = "$(git -C bare.git/wt rev-parse HEAD)"
1835+
'
1836+
18191837
test_expect_success 'refuse fetch to current branch of worktree' '
18201838
test_when_finished "git worktree remove --force wt && git branch -D wt" &&
18211839
git worktree add wt &&

0 commit comments

Comments
 (0)