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