branch: protect branches checked out in all worktrees

Refuse to force-move a branch over the currently checked out branch of
any working tree, not just the current one.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Anders Kaseorg
2021-12-01 14:15:47 -08:00
committed by Junio C Hamano
parent 9fdf4f1db4
commit 593a2a5d06
2 changed files with 16 additions and 4 deletions

View File

@ -168,6 +168,13 @@ test_expect_success 'git branch -M foo bar should fail when bar is checked out'
test_must_fail git branch -M bar foo
'
test_expect_success 'git branch -M foo bar should fail when bar is checked out in worktree' '
git branch -f bar &&
test_when_finished "git worktree remove wt && git branch -D wt" &&
git worktree add wt &&
test_must_fail git branch -M bar wt
'
test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
git checkout -b baz &&
git branch bam &&