On Thu, Dec 2, 2021 at 6:16 AM Anders Kaseorg <andersk@xxxxxxx> wrote: > > 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@xxxxxxx> > --- > branch.c | 13 +++++++++---- > t/t3200-branch.sh | 7 +++++++ > 2 files changed, 16 insertions(+), 4 deletions(-) > > diff --git a/branch.c b/branch.c > index c66b222abd..2cfe496d24 100644 > --- a/branch.c > +++ b/branch.c > @@ -199,7 +199,8 @@ int validate_branchname(const char *name, struct strbuf *ref) > */ > int validate_new_branchname(const char *name, struct strbuf *ref, int force) > { > - const char *head; > + struct worktree **worktrees; > + const struct worktree *wt; > > if (!validate_branchname(name, ref)) > return 0; > @@ -208,9 +209,13 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force) > die(_("a branch named '%s' already exists"), > ref->buf + strlen("refs/heads/")); > > - head = resolve_ref_unsafe("HEAD", 0, NULL, NULL); > - if (!is_bare_repository() && head && !strcmp(head, ref->buf)) > - die(_("cannot force update the current branch")); > + worktrees = get_worktrees(); > + wt = find_shared_symref(worktrees, "HEAD", ref->buf); > + if (wt && !wt->is_bare) > + die(_("cannot force update the branch '%s'" > + "checked out at '%s'"), There is no space between "'%s'" and "checkout". Found this from [1], sorry for reporting this is a bit late. [1] https://github.com/git-l10n/git-po/blob/pot/master/2021-12-22.diff#L315