Merge branch 'ab/enable-i18n'
[gitweb.git] / t / t2018-checkout-branch.sh
index 1caffeac074ed9a8e434a3d6e53c20b00e8672cc..2741262369e40a05cdc6732e4c9e6f04acb63bba 100755 (executable)
@@ -118,12 +118,27 @@ 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 &&
 
        do_checkout branch2 "" -B
 '
 
+test_expect_success 'checkout -B to an existing branch from detached HEAD resets branch to HEAD' '
+       git checkout $(git rev-parse --verify HEAD) &&
+
+       do_checkout branch2 "" -B
+'
+
 test_expect_success 'checkout -B to an existing branch with an explicit ref resets branch to that ref' '
        git checkout branch1 &&
 
@@ -163,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