From: Aniket Gupta Date: Mon, 23 Nov 2026 21:54:24 GMT Subject: Re: [PATCH] history: refuse to rewrite branches used by other worktrees Message-ID: <20261123215424.27553-1-aniketgupta3001@gmail.com> In-Reply-To: Thanks for taking a look! > And is_bare_repository() is true. We skip update_worktree() and > update the 'main' branch via its HEAD, making the index and the > worktree of the worktree at ../wt out of sync, no? True. I am able to repro this. In a bare repo nobody has the branch that HEAD points to checked out, but the check skips it as if the current worktree did. So "git history drop" moves "main" and ../wt shows the changes of the dropped commit as staged. > Perhaps head_target should be initialized to NULL and assigned the > resolution result of HEAD only in a non-bare repository, or something? I think that would fix it. In v2 I'd like to go a bit further though: ask the other worktrees if they use the current branch instead of skipping it by name. That also covers a bare repo and a branch that two worktrees have checked out with "git worktree add --force". Will add tests for both. > I didn't trace all other callers, so there may be other glitches I > did not notice. Went through them. fixup, reword, split, squash, drop all call setup_revwalk() before they open an editor, create a commit or update a ref so they refuse early. Will add a test that runs each of them. > It probably is also worth noting in > the log message that 'drop' updates the worktree while 'reword', > 'split', and 'squash' preserve the tip tree and 'fixup' incorporates > staged changes from the index. Point taken. Will fix the log message and add that.