worktree: add: suppress auto-vivication with --detach and no <branch>
[gitweb.git] / t / t2025-worktree-add.sh
index 8964dec75ab808a440c40de8e320f20f12fb7908..8267411a0ec129a67cde5381cfd79824471d8fd2 100755 (executable)
@@ -83,6 +83,14 @@ test_expect_success 'die the same branch is already checked out' '
        )
 '
 
+test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' '
+       head=$(git -C there rev-parse --git-path HEAD) &&
+       ref=$(git -C there symbolic-ref HEAD) &&
+       rm "$head" &&
+       ln -s "$ref" "$head" &&
+       test_must_fail git -C here checkout newmaster
+'
+
 test_expect_success 'not die the same branch is already checked out' '
        (
                cd here &&
@@ -145,4 +153,44 @@ test_expect_success '"add -b" with <branch> omitted' '
        test_cmp_rev HEAD burble
 '
 
+test_expect_success '"add --detach" with <branch> omitted' '
+       git worktree add --detach fishhook &&
+       git rev-parse HEAD >expected &&
+       git -C fishhook rev-parse HEAD >actual &&
+       test_cmp expected actual &&
+       test_must_fail git -C fishhook symbolic-ref HEAD
+'
+
+test_expect_success '"add" with <branch> omitted' '
+       git worktree add wiffle/bat &&
+       test_cmp_rev HEAD bat
+'
+
+test_expect_success '"add" auto-vivify does not clobber existing branch' '
+       test_commit c1 &&
+       test_commit c2 &&
+       git branch precious HEAD~1 &&
+       test_must_fail git worktree add precious &&
+       test_cmp_rev HEAD~1 precious &&
+       test_path_is_missing precious
+'
+
+test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
+       git worktree add --detach mish/mash &&
+       test_must_fail git rev-parse mash -- &&
+       test_must_fail git -C mish/mash symbolic-ref HEAD
+'
+
+test_expect_success '"add" -b/-B mutually exclusive' '
+       test_must_fail git worktree add -b poodle -B poodle bamboo master
+'
+
+test_expect_success '"add" -b/--detach mutually exclusive' '
+       test_must_fail git worktree add -b poodle --detach bamboo master
+'
+
+test_expect_success '"add" -B/--detach mutually exclusive' '
+       test_must_fail git worktree add -B poodle --detach bamboo master
+'
+
 test_done