From: Aniket Gupta <aniketgupta3001@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Toon Claes <toon@iotcl.com>,
Junio C Hamano <gitster@pobox.com>,
phillip.wood@dunelm.org.uk, Nikita Bobko <nikita@nbobko.com>
Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
Date: Tue, 1 Dec 2026 23:41:53 +0530 [thread overview]
Message-ID: <20261201181153.88521-1-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <aw7I-t56lb5S1Z49@pks.im>
> What follows is a bunch of additional logic to verify whether we'd end
> up rewriting any commit that is checked out anywhere. Would it make
> sense to maybe split this up into a sequence of commits, where each of
> the commits introduces one such new check?
I feel that there are no separate checks left to split now, primarily
because the branches that are checked out, rebased, bisected or going to
be updated by "rebase --update-refs", all come from one list in
branch.c, and history.c only has to check against it. A separate commit
for the new function in branch.c would add a function that nothing uses
yet, so maybe we can keep it as one patch?
> s/int/size_t/
The check has moved to branch.c, so both worktree loops shall be gone in
v3.
> So doesn't this make `rebase_in_progress()` obsolete, at least for
> worktrees other than the current one?
I dont think so. It only looks at the current worktree, which
is_shared_symref() skips. If the current worktree is rebasing a detached
HEAD, there is no branch to refuse, so this function is what stops us
from rewriting HEAD in the middle of it. Rebases of a branch in other
worktrees will be covered by the list in branch.c in v3.
> What this function doesn't check is whether any of the worktrees is
> detached on a specific commit ID that we'd end up rewriting. But I
> think that's actually intentional, as it doesn't really matter for our
> usecase of git-history(1).
It is intentional. I had tried a worktree that is detached on a
rewritten commit: its HEAD stays where it was and its status is clean.
> 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?
Yup. As Phillip says, it is confusing if the HEAD of one worktree
changes because a branch was rewritten from another. That is why head
mode refuses the current branch when another worktree uses it. In v2,
the current branch could still be rewritten while another worktree's
"rebase --update-refs" was about to update it.
> 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.
Yes v2 missed the --update-refs case, and v3 will fix it. The refs we
check are the same ones that get updated as both come from the same
commits. We check early on purpose. If we waited, "reword" and the other
commands would first ask for a message and only then refuse.
> 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?
This indeed is a gap. If a worktree starts using a branch while the
history is being rewritten, for eg while the editor is open, we will not
notice. I repro'd that with a "reword" editor that adds a worktree.
Phillip sketched a way to close it with a file that records the refs
being rewritten and that other worktrees and commands check. The checks
seemed like a good first step. Maybe we can leave that for later?
prev parent reply other threads:[~2026-12-01 18:12 UTC|newest]
Thread overview: 22+ 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
2026-12-02 6:23 ` Patrick Steinhardt
2026-12-01 18:11 ` Aniket Gupta [this message]
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=20261201181153.88521-1-aniketgupta3001@gmail.com \
--to=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