diff options
author | Eric Sunshine <sunshine@sunshineco.com> | 2015-07-06 19:30:45 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-07-06 20:07:44 +0200 |
commit | c990a4c11dd7bb671da1b30e14568ad986621488 (patch) | |
tree | ec516c7ba3f8aa6d76c6f03bfd7146cdb9388c03 /t | |
parent | Documentation/git-worktree: add EXAMPLES section (diff) | |
download | git-c990a4c11dd7bb671da1b30e14568ad986621488.tar.xz git-c990a4c11dd7bb671da1b30e14568ad986621488.zip |
checkout: fix bug with --to and relative HEAD
Given "git checkout --to <path> HEAD~1", the new worktree's HEAD should
begin life at the current branch's HEAD~1, however, it actually ends up
at HEAD~2. This happens because:
1. git-checkout resolves HEAD~1
2. to satisfy is_git_directory(), prepare_linked_worktree() creates
a HEAD for the new worktree with the value of the resolved HEAD~1
3. git-checkout re-invokes itself with the same arguments within the
new worktree to populate the worktree
4. the sub git-checkout resolves HEAD~1 relative to its own HEAD,
which is the resolved HEAD~1 from the original invocation,
resulting unexpectedly and incorrectly in HEAD~2 (relative to the
original)
Fix this by unconditionally assigning the current worktree's HEAD as the
value of the new worktree's HEAD.
As a side-effect, this change also eliminates a dependence within
prepare_linked_checkout() upon 'struct branch_info'. The plan is to
eventually relocate "git checkout --to" functionality to "git worktree
add", and worktree.c won't have knowledge of 'struct branch_info', so
removal of this dependency is a step toward that goal.
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t2025-checkout-to.sh | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh index a8d93366f6..0fd731b4bc 100755 --- a/t/t2025-checkout-to.sh +++ b/t/t2025-checkout-to.sh @@ -134,4 +134,14 @@ test_expect_success 'checkout with grafts' ' test_cmp expected actual ' +test_expect_success 'checkout --to from relative HEAD' ' + test_commit a && + test_commit b && + test_commit c && + git rev-parse HEAD~1 >expected && + git checkout --to relhead HEAD~1 && + git -C relhead rev-parse HEAD >actual && + test_cmp expected actual +' + test_done |