summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--branch.c4
-rwxr-xr-xt/t7201-co.sh14
2 files changed, 11 insertions, 7 deletions
diff --git a/branch.c b/branch.c
index b1e59f2196..6a750574fd 100644
--- a/branch.c
+++ b/branch.c
@@ -129,7 +129,9 @@ void create_branch(const char *head,
die("Cannot setup tracking information; starting point is not a branch.");
break;
case 1:
- /* Unique completion -- good */
+ /* Unique completion -- good, only if it is a real ref */
+ if (track == BRANCH_TRACK_EXPLICIT && !strcmp(real_ref, "HEAD"))
+ die("Cannot setup tracking information; starting point is not a branch.");
break;
default:
die("Ambiguous object name: '%s'.", start_name);
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index fbec70d3c6..ee2cab6bb2 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -330,12 +330,14 @@ test_expect_success \
test "$(git config branch.track2.merge)"
git config branch.autosetupmerge false'
-test_expect_success \
- 'checkout w/--track from non-branch HEAD fails' '
- git checkout -b delete-me master &&
- rm .git/refs/heads/delete-me &&
- test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
- test_must_fail git checkout --track -b track'
+test_expect_success 'checkout w/--track from non-branch HEAD fails' '
+ git checkout master^0 &&
+ test_must_fail git symbolic-ref HEAD &&
+ test_must_fail git checkout --track -b track &&
+ test_must_fail git rev-parse --verify track &&
+ test_must_fail git symbolic-ref HEAD &&
+ test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)"
+'
test_expect_success 'checkout an unmerged path should fail' '
rm -f .git/index &&