Code

Merge branch 'jc/maint-verify-objects-remove-pessimism' into maint-1.7.8
[git.git] / t / t2018-checkout-branch.sh
index fa69016381b0196c49472af51e36948ec7c5a2a9..2741262369e40a05cdc6732e4c9e6f04acb63bba 100755 (executable)
@@ -118,6 +118,15 @@ test_expect_success 'checkout -b to an existing branch fails' '
        test_must_fail do_checkout branch2 $HEAD2
 '
 
+test_expect_success 'checkout -b to @{-1} fails with the right branch name' '
+       git reset --hard HEAD &&
+       git checkout branch1 &&
+       git checkout branch2 &&
+       echo  >expect "fatal: A branch named '\''branch1'\'' already exists." &&
+       test_must_fail git checkout -b @{-1} 2>actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
        git checkout branch1 &&
 
@@ -169,4 +178,24 @@ test_expect_success 'checkout -f -B to an existing branch with mergeable changes
        test_must_fail test_dirty_mergeable
 '
 
+test_expect_success 'checkout -b <describe>' '
+       git tag -f -m "First commit" initial initial &&
+       git checkout -f change1 &&
+       name=$(git describe) &&
+       git checkout -b $name &&
+       git diff --exit-code change1 &&
+       echo "refs/heads/$name" >expect &&
+       git symbolic-ref HEAD >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'checkout -B to the current branch works' '
+       git checkout branch1 &&
+       git checkout -B branch1-scratch &&
+
+       setup_dirty_mergeable &&
+       git checkout -B branch1-scratch initial &&
+       test_dirty_mergeable
+'
+
 test_done