Re: [PATCH] history: refuse to rewrite branches used by other worktrees
- From
- Aniket Gupta <aniketgupta3001@gmail.com>
- Date
- Nov 23, 2026, 21:54 UTC
- Message-ID
- <20261123215431.27574-1-aniketgupta3001@gmail.com>
- In-Reply-To
- <a0ebd98f-669e-4ff2-bca2-cfd5da5a7316@gmail.com>
Thanks for taking a look!
> "also" is unnecessary here
Will drop this.
> The staged changes it shows were made by "git history" - they did not > appear from nowhere. An alternative to refusing to run would be to > update those worktrees if they are clean, but failing is the simpler > option to implement.
Fair point, will reword. I stayed with refusing as it is simpler. Updating clean worktrees could come later if people want it.
> fail to notice it is checked out elsewhere. That's not a problem that > needs solving here though.
Noted. For the current branch v2 asks each worktree, so it does not depend on branch_checked_out() there. The other branches still go through it.
> What happens if a rebase is running in the same worktree as the user > tries to run "git history"?
It is refused. HEAD is detached then, so the branch being rebased is not the one this worktree has checked out, and it gets treated like any other branch in use. There is a test for it, but the commit message does not contain this. Will fix.
In that case --update-refs=head is not refused: it only rewrites the detached HEAD, same as before. I tried fixup, reword, drop and squash that way, and "git rebase --continue" finished fine each time.
> Does --update-refs=head try to update the current branch? If so we > should check that is not being written somewhere else.
Yes, it updates the branch HEAD points to and nothing checks it today. I could repro it with "git worktree add --force" on the same branch: after a fixup in one of them, the other shows a staged change. Good catch, will add the check.
> we should say what "git history" refuses to do.
Will fix.
> We should also prevent rebase from rewriting a branch that is being > rewritten by "git history" but that can come later.
Agreed, that can come later.
> This is correct, but it duplicates the revision walk we're already > doing when looking for merge commits.
Makes sense. I gave it a try and it works. One point: the branch pointing at the rewritten commit itself is not part of the walk, so I look at its decorations too. Rewriting a commit that another worktree's branch points at goes through without it. Will do it like this in v2.