Merge branch 'jk/filter-branch-require-clean-work-tree' into maint
[gitweb.git] / t / t2018-checkout-branch.sh
index 741d84257b5704b059074d5376cd10f3d358daba..75874e85dfbcae8ea9634693a93524841b741559 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 &&
 
@@ -174,4 +189,12 @@ test_expect_success 'checkout -b <describe>' '
        test_cmp expect actual
 '
 
+test_expect_success 'checkout -B to the current branch fails before merging' '
+       git checkout branch1 &&
+       setup_dirty_mergeable &&
+       git commit -mfooble &&
+       test_must_fail git checkout -B branch1 initial &&
+       test_must_fail test_dirty_mergeable
+'
+
 test_done