Fourth batch
[gitweb.git] / t / t3200-branch.sh
index acb16b62dda3abd87bfaad7658390c683b15e176..411a70b0ce966f196b516053f2b1ea35ad03bef2 100755 (executable)
@@ -206,18 +206,22 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou
        git worktree add -f bazdir2 baz &&
        git branch -M baz bam &&
        test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
-       test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
+       test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam &&
+       rm -r bazdir bazdir2 &&
+       git worktree prune
 '
 
 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
        git checkout -b baz &&
-       git worktree add -f bazdir3 baz &&
+       git worktree add -f bazdir baz &&
        (
-               cd bazdir3 &&
+               cd bazdir &&
                git branch -M baz bam &&
                test $(git rev-parse --abbrev-ref HEAD) = bam
        ) &&
-       test $(git rev-parse --abbrev-ref HEAD) = bam
+       test $(git rev-parse --abbrev-ref HEAD) = bam &&
+       rm -r bazdir &&
+       git worktree prune
 '
 
 test_expect_success 'git branch -M master should work when master is checked out' '
@@ -268,6 +272,30 @@ test_expect_success 'git branch --list -d t should fail' '
        test_must_fail git rev-parse refs/heads/t
 '
 
+test_expect_success 'deleting checked-out branch from repo that is a submodule' '
+       test_when_finished "rm -rf repo1 repo2" &&
+
+       git init repo1 &&
+       git init repo1/sub &&
+       test_commit -C repo1/sub x &&
+       git -C repo1 submodule add ./sub &&
+       git -C repo1 commit -m "adding sub" &&
+
+       git clone --recurse-submodules repo1 repo2 &&
+       git -C repo2/sub checkout -b work &&
+       test_must_fail git -C repo2/sub branch -D work
+'
+
+test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
+       test_when_finished "rm -rf nonbare base secondary" &&
+
+       git init nonbare &&
+       test_commit -C nonbare x &&
+       git clone --bare nonbare bare &&
+       git -C bare worktree add --detach ../secondary master &&
+       git -C secondary branch -D master
+'
+
 test_expect_success 'git branch --list -v with --abbrev' '
        test_when_finished "git branch -D t" &&
        git branch t &&
@@ -780,7 +808,9 @@ test_expect_success 'test deleting branch without config' '
 test_expect_success 'deleting currently checked out branch fails' '
        git worktree add -b my7 my7 &&
        test_must_fail git -C my7 branch -d my7 &&
-       test_must_fail git branch -d my7
+       test_must_fail git branch -d my7 &&
+       rm -r my7 &&
+       git worktree prune
 '
 
 test_expect_success 'test --track without .fetch entries' '