Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-22 00:53:12 +0300
committerJunio C Hamano <gitster@pobox.com>2023-07-22 01:30:57 +0300
commit4970bedef2e077f78baac5c6e825d17786be735b (patch)
treeda5e442f341eed31aa45a152b71c2e3598add47f /branch.c
parentaa9166bcc0ba654fc21f198a30647ec087f733ed (diff)
branch: update the message to refuse touching a branch in-use
The "git branch -f" command can refuse to force-update a branch that is used by another worktree. The original rationale for this behaviour was that updating a branch that is checked out in another worktree, without making a matching change to the index and the working tree files in that worktree, will lead to a very confused user. "git diff HEAD" will no longer give a useful patch, because HEAD is a commit unrelated to what the index and the working tree in the worktree were based on, for example. These days, the same mechanism also protects branches that are being rebased or bisected, and the same machanism is expected to be the right place to add more checks, when we decide to protect branches undergoing other kinds of operations. We however forgot to rethink the messaging, which originally said that we are refusing to touch the branch because it is "checked out" elsewhere, when d2ba271a (branch: check for bisects and rebases, 2022-06-14) started to protect branches that are being rebased or bisected. The spirit of the check has always been that we do not want to disrupt the use of the same branch in other worktrees. Let's reword the message slightly to say that the branch is "used by" another worktree, instead of "checked out". We could teach the branch.c:prepare_checked_out_branches() function to remember why it decided that a particular branch needs protecting (i.e. was it because it was checked out? being bisected? something else?) in addition to which worktree the branch was in use, and use that in the error message to say "you cannot force update this branch because it is being bisected in the worktree X", etc., but it is dubious that such extra complexity is worth it. The message already tells which directory the worktree in question is, and it should be just a "chdir" away for the user to find out what state it is in, if the user felt curious enough. So let's not go there yet. Helped-by: Josh Sref <jsoref@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/branch.c b/branch.c
index cdf70b0ef0..3e4684f79f 100644
--- a/branch.c
+++ b/branch.c
@@ -471,7 +471,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
if ((path = branch_checked_out(ref->buf)))
die(_("cannot force update the branch '%s' "
- "checked out at '%s'"),
+ "used by worktree at '%s'"),
ref->buf + strlen("refs/heads/"), path);
return 1;