diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-12-28 01:52:24 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-12-28 01:52:24 +0300 |
commit | f09e74175dfa5b46587dab3c5dcbad16e9586de3 (patch) | |
tree | 98626534b7796b0deb7948757fc5ec78b58166b2 /t | |
parent | 055bb6e9969085777b7fab83e3fee0017654f134 (diff) | |
parent | b23285a921a84c3b83d9aaca31afedf290c59254 (diff) |
Merge branch 'jc/checkout-B-branch-in-use'
"git checkout -B <branch> [<start-point>]" allowed a branch that is
in use in another worktree to be updated and checked out, which
might be a bit unexpected. The rule has been tightened, which is a
breaking change. "--ignore-other-worktrees" option is required to
unbreak you, if you are used to the current behaviour that "-B"
overrides the safety.
* jc/checkout-B-branch-in-use:
checkout: forbid "-B <branch>" from touching a branch used elsewhere
checkout: refactor die_if_checked_out() caller
Diffstat (limited to 't')
-rwxr-xr-x | t/t2060-switch.sh | 2 | ||||
-rwxr-xr-x | t/t2400-worktree-add.sh | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index e247a4735b..c91c4db936 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -170,8 +170,10 @@ test_expect_success 'switch back when temporarily detached and checked out elsew # we test in both worktrees to ensure that works # as expected with "first" and "next" worktrees test_must_fail git -C wt1 switch shared && + test_must_fail git -C wt1 switch -C shared && git -C wt1 switch --ignore-other-worktrees shared && test_must_fail git -C wt2 switch shared && + test_must_fail git -C wt2 switch -C shared && git -C wt2 switch --ignore-other-worktrees shared ' diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 245656b53a..b7b667270a 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -126,6 +126,28 @@ test_expect_success 'die the same branch is already checked out' ' ) ' +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 + ) +' + 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) && |