Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Patrick Steinhardt <ps@pks.im>, Aniket Gupta <aniketgupta3001@gmail.com>
Cc: git@vger.kernel.org, Toon Claes <toon@iotcl.com>,
	Junio C Hamano <gitster@pobox.com>,
	Nikita Bobko <nikita@nbobko.com>
Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
Date: Tue, 1 Dec 2026 16:37:37 +0000	[thread overview]
Message-ID: <3d2e9653-87ce-48f4-a154-2b5a1a31a84c@gmail.com> (raw)
In-Reply-To: <aw7I-t56lb5S1Z49@pks.im>

Hi Patrick

On 01/12/2026 13:18, Patrick Steinhardt wrote:
> 
> I'm probably missing something, but the way we handle `head_target`
> seems weird to me. It is getting resolved to whatever we have checked
> out in the current worktree. But do we even care about whether the
> currently checked out branch is used anywhere else?

It's confusing if HEAD gets updated in one worktree because a branch was 
rewritten in a different worktree. That's why we have checks in "git 
rebase" to avoid rewriting branches that are checked out in other worktrees.

> What I would have expected us to do is that we take the list of pending
> ref updates that we compute in `handle_reference_updates()` and verify
> that none of those refs that we're updating is checked out or being
> rebased/bisected. But as far as I can see, this check here comes before
> we have even computed those ref updates in the first place.

We need to do the check before rewriting so that a user running "git 
history reword" does not spend time editing the commit message, only for 
us to refuse to update any refs.

> So we're verifying the pre-rewrite state, not the state after already
> having performed the history rewrite where the ref updates are now
> pending. And consequently, I think we don't reject some updates that may
> happen in worktrees.

Ideally we'd find all the branches that we want to rewrite, write those 
to "$GIT_DIR/history/ref-updates", then walk all the other worktrees 
checking which branch is checked out, being rebased etc. and read each 
worktree's "$GIT_DIR/history/ref-updates" to see if there is an active 
"git history" command rewriting the same branch. If a branch that we 
want to rewrite is being rewritten by a command running in another 
worktree we'd remove "$GIT_DIR/history/ref-updates" and error out. "git 
checkout", "git rebase" etc. would also check 
"$GIT_DIR/history/ref-updates" as well. By writing the list of refs we 
want to update before checking if any other worktree is updating them 
and removing the file after we've rewritten them, I think we avoid races 
where two commands started at the same time try and update the same 
branch. I don't think we necessarily need to implement that all at once 
though, the checks added in this patch are a good first step.

Thanks

Phillip

> But even if we detected all of them, we would now be racy as we should
> perform the validation at the point in time where we have already
> gathered expected old and new commit IDs for the ref updates, shouldn't
> we?
> 
> I may be missing something very obvious, but I think as-is these checks
> are somewhat broken?
> 
> Thanks!
> 
> Patrick


  reply	other threads:[~2026-12-01 16:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:39 [PATCH] history: refuse to rewrite branches used by other worktrees Aniket Gupta
2026-11-23 13:10 ` Phillip Wood
2026-11-23 21:54   ` Aniket Gupta
2026-11-24 10:49     ` Phillip Wood
2026-11-24 14:09       ` Aniket Gupta
2026-11-23 20:14 ` Junio C Hamano
2026-11-23 21:54   ` Aniket Gupta
2026-11-27 17:32 ` [PATCH v2] " Aniket Gupta
2026-11-28  0:12   ` Junio C Hamano
2026-11-28  7:37     ` Aniket Gupta
2026-11-30 11:31   ` Toon Claes
2026-11-30 12:15     ` Aniket Gupta
2026-11-30 14:39     ` Phillip Wood
2026-11-30 17:13       ` Aniket Gupta
2026-11-30 14:49   ` Phillip Wood
2026-11-30 17:13     ` Aniket Gupta
2026-12-01 16:39       ` Phillip Wood
2026-12-01 17:36         ` Aniket Gupta
2026-12-01 13:18   ` Patrick Steinhardt
2026-12-01 16:37     ` Phillip Wood [this message]
2026-12-01 18:11     ` Aniket Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d2e9653-87ce-48f4-a154-2b5a1a31a84c@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=aniketgupta3001@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nikita@nbobko.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    --cc=toon@iotcl.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox