branch: test for failures while renaming branches
commit2e8af499ff6e166a5f54f18cf3d1fa8f5d9bde38
authorRubén Justo <rjusto@gmail.com>
Sun, 26 Mar 2023 22:33:02 +0000 (27 00:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2023 16:40:14 +0000 (27 09:40 -0700)
treeb0c12fdd47381043ee46c5e6e5b97d78b2094e96
parent73876f4861cd3d187a4682290ab75c9dccadbc56
branch: test for failures while renaming branches

When we introduced replace_each_worktree_head_symref() in 70999e9cec
(branch -m: update all per-worktree HEADs, 2016-03-27), we implemented a
best effort approach.

If we are asked to rename a branch that is simultaneously checked out in
multiple worktrees, we try to update all of those worktrees.  If we fail
updating any of them, we die() as a signal that something has gone
wrong.  However, at this point, the branch ref has already been renamed
and also updated the HEADs of the successfully updated worktrees.
Despite returning an error, we do not try to rollback those changes.

Let's add a test to notice if we change this behavior in the future.

In next commits we will change replace_each_worktree_head_symref() to
work more closely with its only caller, copy_or_rename_branch().  Let's
move the former closer to its caller, to facilitate those changes.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c
branch.h
builtin/branch.c
t/t3200-branch.sh