@matheusbsbs / matheus-bagliano / commits / 51a94af845
Fork 0

Fix "checkout --track -b newbranch" on detached HEAD

The test to make sure that checkout fails when --track was asked for and we cannot set up tracking information in t7201 was wrong, and it turns out that the implementation for that feature itself was buggy. This fixes it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 16, 2008 at 23:37 UTC 51a94af845cb3f797abd638478834721d7295af7
2 files changed +11 -7
branch.c
+3 -1
@@ -129,7 +129,9 @@ void create_branch(const char *head,
129 die("Cannot setup tracking information; starting point is not a branch.");
130 break;
131 case 1:
132 - /* Unique completion -- good */
132 + /* Unique completion -- good, only if it is a real ref */
133 + if (track == BRANCH_TRACK_EXPLICIT && !strcmp(real_ref, "HEAD"))
134 + die("Cannot setup tracking information; starting point is not a branch.");
135 break;
136 default:
137 die("Ambiguous object name: '%s'.", start_name);
t/t7201-co.sh
+8 -6
@@ -330,12 +330,14 @@ test_expect_success \
330 test "$(git config branch.track2.merge)"
331 git config branch.autosetupmerge false'
332
333 -test_expect_success \
334 - 'checkout w/--track from non-branch HEAD fails' '
335 - git checkout -b delete-me master &&
336 - rm .git/refs/heads/delete-me &&
337 - test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
338 - test_must_fail git checkout --track -b track'
333 +test_expect_success 'checkout w/--track from non-branch HEAD fails' '
334 + git checkout master^0 &&
335 + test_must_fail git symbolic-ref HEAD &&
336 + test_must_fail git checkout --track -b track &&
337 + test_must_fail git rev-parse --verify track &&
338 + test_must_fail git symbolic-ref HEAD &&
339 + test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)"
340 +'
341
342 test_expect_success 'checkout an unmerged path should fail' '
343 rm -f .git/index &&