Skip to content

Commit 894ea94

Browse files
rjustogitster
authored andcommitted
switch: reject if the branch is already checked out elsewhere (test)
Since 5883034 (checkout: reject if the branch is already checked out elsewhere) in normal use, we do not allow multiple worktrees having the same checked out branch. 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 279f42f commit 894ea94

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

t/t2060-switch.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,33 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
146146
test_cmp_config "" --default "" branch.main2.merge
147147
'
148148

149+
test_expect_success 'switch back when temporarily detached and checked out elsewhere ' '
150+
test_when_finished "
151+
git worktree remove wt1 ||:
152+
git worktree remove wt2 ||:
153+
git checkout - ||:
154+
git branch -D shared ||:
155+
" &&
156+
git checkout -b shared &&
157+
test_commit shared-first &&
158+
HASH1=$(git rev-parse --verify HEAD) &&
159+
test_commit shared-second &&
160+
test_commit shared-third &&
161+
HASH2=$(git rev-parse --verify HEAD) &&
162+
git worktree add wt1 -f shared &&
163+
git -C wt1 bisect start &&
164+
git -C wt1 bisect good $HASH1 &&
165+
git -C wt1 bisect bad $HASH2 &&
166+
git worktree add wt2 -f shared &&
167+
git -C wt2 bisect start &&
168+
git -C wt2 bisect good $HASH1 &&
169+
git -C wt2 bisect bad $HASH2 &&
170+
# we test in both worktrees to ensure that works
171+
# as expected with "first" and "next" worktrees
172+
test_must_fail git -C wt1 switch shared &&
173+
git -C wt1 switch --ignore-other-worktrees shared &&
174+
test_must_fail git -C wt2 switch shared &&
175+
git -C wt2 switch --ignore-other-worktrees shared
176+
'
177+
149178
test_done

0 commit comments

Comments
 (0)