]> git.ipfire.org Git - thirdparty/git.git/commit - t/t2060-switch.sh
checkout: forbid "-B <branch>" from touching a branch used elsewhere
authorJunio C Hamano <gitster@pobox.com>
Thu, 23 Nov 2023 06:00:31 +0000 (15:00 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Dec 2023 15:48:17 +0000 (07:48 -0800)
commitb23285a921a84c3b83d9aaca31afedf290c59254
tree9d60e7089e73328124c9b6603547e3dd6769ac3f
parent9263c40a0a0c299db59b8a64e87b95026a28812a
checkout: forbid "-B <branch>" from touching a branch used elsewhere

"git checkout -B <branch> [<start-point>]", being a "forced" version
of "-b", switches to the <branch>, after optionally resetting its
tip to the <start-point>, even if the <branch> is in use in another
worktree, which is somewhat unexpected.

Protect the <branch> using the same logic that forbids "git checkout
<branch>" from touching a branch that is in use elsewhere.

This is a breaking change that may deserve backward compatibliity
warning in the Release Notes.  The "--ignore-other-worktrees" option
can be used as an escape hatch if the finger memory of existing
users depend on the current behaviour of "-B".

Reported-by: Willem Verstraeten <willem.verstraeten@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-checkout.txt
Documentation/git-switch.txt
builtin/checkout.c
t/t2060-switch.sh
t/t2400-worktree-add.sh