Git development
 help / color / mirror / Atom feed
From: Aniket Gupta <aniketgupta3001@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
	Toon Claes <toon@iotcl.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	Nikita Bobko <nikita@nbobko.com>
Subject: Re: [PATCH] history: refuse to rewrite branches used by other worktrees
Date: Tue, 24 Nov 2026 03:24:24 +0530	[thread overview]
Message-ID: <20261123215424.27553-1-aniketgupta3001@gmail.com> (raw)
In-Reply-To: <xmqqa4mz5mr8.fsf@gitster.g>

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.

  reply	other threads:[~2026-11-23 21:54 UTC|newest]

Thread overview: 16+ 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 [this message]
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

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=20261123215424.27553-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