checkout: clean up half-prepared directories in --to mode
[gitweb.git] / t / t2025-checkout-to.sh
index 49634157bf66e9e7d3b31edd94380678a1ade163..e2db07859b36d752bb0784918f9e1571a150a4f8 100755 (executable)
@@ -17,14 +17,21 @@ test_expect_success 'checkout --to an existing worktree' '
        test_must_fail git checkout --detach --to existing master
 '
 
+test_expect_success 'checkout --to refuses to checkout locked branch' '
+       test_must_fail git checkout --to zere master &&
+       ! test -d zere &&
+       ! test -d .git/worktrees/zere
+'
+
 test_expect_success 'checkout --to a new worktree' '
-       git checkout --to here master &&
+       git rev-parse HEAD >expect &&
+       git checkout --detach --to here master &&
        (
                cd here &&
                test_cmp ../init.t init.t &&
-               git symbolic-ref HEAD >actual &&
-               echo refs/heads/master >expect &&
-               test_cmp expect actual &&
+               test_must_fail git symbolic-ref HEAD &&
+               git rev-parse HEAD >actual &&
+               test_cmp ../expect actual &&
                git fsck
        )
 '
@@ -42,7 +49,7 @@ test_expect_success 'checkout --to a new worktree from a subdir' '
 test_expect_success 'checkout --to from a linked checkout' '
        (
                cd here &&
-               git checkout --to nested-here master &&
+               git checkout --detach --to nested-here master &&
                cd nested-here &&
                git fsck
        )
@@ -60,4 +67,18 @@ test_expect_success 'checkout --to a new worktree creating new branch' '
        )
 '
 
+test_expect_success 'die the same branch is already checked out' '
+       (
+               cd here &&
+               test_must_fail git checkout newmaster
+       )
+'
+
+test_expect_success 'not die on re-checking out current branch' '
+       (
+               cd there &&
+               git checkout newmaster
+       )
+'
+
 test_done