Skip to content

Commit 279f42f

Browse files
rjustogitster
authored andcommitted
rebase: refuse to switch to a branch already checked out elsewhere (test)
In b5cabb4 (rebase: refuse to switch to branch already checked out elsewhere, 2020-02-23) we add a condition to prevent a rebase operation involving a switch to a branch that is already checked out in another worktree. A bug has recently been fixed that caused this to not work as expected. Let's add a test to notice if this changes in the future. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faa4d59 commit 279f42f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

t/t3400-rebase.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,20 @@ test_expect_success 'switch to branch checked out here' '
388388
git rebase main main
389389
'
390390

391+
test_expect_success 'switch to branch checked out elsewhere fails' '
392+
test_when_finished "
393+
git worktree remove wt1 &&
394+
git worktree remove wt2 &&
395+
git branch -d shared
396+
" &&
397+
git worktree add wt1 -b shared &&
398+
git worktree add wt2 -f shared &&
399+
# we test in both worktrees to ensure that works
400+
# as expected with "first" and "next" worktrees
401+
test_must_fail git -C wt1 rebase shared shared &&
402+
test_must_fail git -C wt2 rebase shared shared
403+
'
404+
391405
test_expect_success 'switch to branch not checked out' '
392406
git checkout main &&
393407
git branch other &&

0 commit comments

Comments
 (0)