diff options
Diffstat (limited to 't/t2400-worktree-add.sh')
-rwxr-xr-x | t/t2400-worktree-add.sh | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 051363acbb..c28c04133c 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -121,7 +121,30 @@ test_expect_success '"add" worktree creating new branch' ' test_expect_success 'die the same branch is already checked out' ' ( cd here && - test_must_fail git checkout newmain + test_must_fail git checkout newmain 2>actual && + grep "already used by worktree at" actual + ) +' + +test_expect_success 'refuse to reset a branch in use elsewhere' ' + ( + cd here && + + # we know we are on detached HEAD but just in case ... + git checkout --detach HEAD && + git rev-parse --verify HEAD >old.head && + + git rev-parse --verify refs/heads/newmain >old.branch && + test_must_fail git checkout -B newmain 2>error && + git rev-parse --verify refs/heads/newmain >new.branch && + git rev-parse --verify HEAD >new.head && + + grep "already used by worktree at" error && + test_cmp old.branch new.branch && + test_cmp old.head new.head && + + # and we must be still on the same detached HEAD state + test_must_fail git symbolic-ref HEAD ) ' @@ -414,7 +437,7 @@ test_wt_add_orphan_hint () { git -C repo switch --orphan noref && test_must_fail git -C repo worktree add $opts foobar/ 2>actual && ! grep "error: unknown switch" actual && - grep "hint: If you meant to create a worktree containing a new orphan branch" actual && + grep "hint: If you meant to create a worktree containing a new unborn branch" actual && if [ $use_branch -eq 1 ] then grep -E "^hint: +git worktree add --orphan -b [^ ]+ [^ ]+$" actual @@ -435,7 +458,7 @@ test_expect_success "'worktree add' doesn't show orphan hint in bad/orphan HEAD (cd repo && test_commit commit) && test_must_fail git -C repo worktree add --quiet foobar_branch foobar/ 2>actual && ! grep "error: unknown switch" actual && - ! grep "hint: If you meant to create a worktree containing a new orphan branch" actual + ! grep "hint: If you meant to create a worktree containing a new unborn branch" actual ' test_expect_success 'local clone from linked checkout' ' @@ -467,7 +490,8 @@ test_expect_success 'put a worktree under rebase' ' cd under-rebase && set_fake_editor && FAKE_LINES="edit 1" git rebase -i HEAD^ && - git worktree list | grep "under-rebase.*detached HEAD" + git worktree list >actual && + grep "under-rebase.*detached HEAD" actual ) ' @@ -508,7 +532,8 @@ test_expect_success 'checkout a branch under bisect' ' git bisect start && git bisect bad && git bisect good HEAD~2 && - git worktree list | grep "under-bisect.*detached HEAD" && + git worktree list >actual && + grep "under-bisect.*detached HEAD" actual && test_must_fail git worktree add new-bisect under-bisect && ! test -d new-bisect ) @@ -708,9 +733,9 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' ' test_dwim_orphan () { local info_text="No possible source branch, inferring '--orphan'" && local fetch_error_text="fatal: No local or remote refs exist despite at least one remote" && - local orphan_hint="hint: If you meant to create a worktree containing a new orphan branch" && + local orphan_hint="hint: If you meant to create a worktree containing a new unborn branch" && local invalid_ref_regex="^fatal: invalid reference: " && - local bad_combo_regex="^fatal: '[-a-z]*' and '[-a-z]*' cannot be used together" && + local bad_combo_regex="^fatal: options '[-a-z]*' and '[-a-z]*' cannot be used together" && local git_ns="repo" && local dashc_args="-C $git_ns" && |