summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-07-06 17:30:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-06 18:07:44 (GMT)
commitc990a4c11dd7bb671da1b30e14568ad986621488 (patch)
treeec516c7ba3f8aa6d76c6f03bfd7146cdb9388c03 /t
parent96454597562dade701fbfee19891482a97456138 (diff)
downloadgit-c990a4c11dd7bb671da1b30e14568ad986621488.zip
git-c990a4c11dd7bb671da1b30e14568ad986621488.tar.gz
git-c990a4c11dd7bb671da1b30e14568ad986621488.tar.bz2
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-xt/t2025-checkout-to.sh10
1 files changed, 10 insertions, 0 deletions
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
index a8d9336..0fd731b 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