From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Pablo Sabater <pabloosabaterr@gmail.com>
Subject: Re: [PATCH v2 9/9] builtin/history: implement "drop" subcommand
Date: Thu, 4 Jun 2026 11:02:14 +0200 [thread overview]
Message-ID: <aiE_FtbkLVjXdSVX@pks.im> (raw)
In-Reply-To: <xmqqmrxbqir4.fsf@gitster.g>
On Thu, Jun 04, 2026 at 08:58:07AM +0900, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > +static int update_worktree(struct repository *repo,
> > + const struct commit *old_head,
> > + const struct commit *new_head,
> > + bool dry_run)
> > +{
> > + struct reset_head_opts opts = {
> > + .oid_from = &old_head->object.oid,
> > + .oid = &new_head->object.oid,
> > + .flags = RESET_HEAD_SKIP_REF_UPDATES,
> > + };
> > + if (dry_run)
> > + opts.flags |= RESET_HEAD_DRY_RUN;
> > + return reset_head(repo, &opts);
> > +}
> > + ...
> > + /*
> > + * If HEAD will move as a result of the rewrite then we'll have to
> > + * merge in the changes into the worktree and index. This merge can of
> > + * course conflict, which will cause the whole operation to abort.
> > + *
> > + * If we had already updated the refs at that point then we'd have an
> > + * inconsistent repository state. So we first perform a dry-run merge
> > + * here before updating refs.
> > + */
> > + if (!dry_run && !is_bare_repository()) {
> > + ret = find_head_tree_change(repo, &result, &old_head,
> > + &new_head, &head_moves);
> > + if (ret < 0)
> > + goto out;
> > +
> > + if (head_moves && update_worktree(repo, old_head, new_head, true) < 0) {
> > + ret = error(_("dropping this commit would "
> > + "overwrite local changes; aborting"));
> > + goto out;
> > + }
> > + }
>
> This block is skipped under --dry-run, but update_worktree is
> equipped to (and indeed run unconditionally here) run in the dry-run
> mode. Does it mean that "git history drop --dry-run" that user runs
> to see which refs may be updated will not get warned about possible
> worktree conflicts that would prevent the real run from happening?
> Unless there is a compelling reason not to, I think --dry-run should
> be a close simulation of what would happen without it.
That's an oversight on my part indeed. We _should_ run this block with
dry-run, and it shows that we're definitely lacking test coverage here.
Will fix, thanks!
Patrick
prev parent reply other threads:[~2026-06-04 9:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 15:36 [PATCH 0/2] builtin/history: introduce "drop" subcommand Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 1/2] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 2/2] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-01 23:43 ` Junio C Hamano
2026-06-03 10:06 ` Patrick Steinhardt
2026-06-02 7:31 ` Pablo Sabater
2026-06-03 10:06 ` Patrick Steinhardt
2026-06-03 16:13 ` [PATCH v2 0/9] builtin/history: introduce " Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 1/9] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 2/9] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 3/9] reset: modernize flags passed to `reset_head()` Patrick Steinhardt
2026-06-03 18:01 ` Kristoffer Haugsbakk
2026-06-03 16:14 ` [PATCH v2 4/9] reset: introduce dry-run mode Patrick Steinhardt
2026-06-03 18:18 ` Kristoffer Haugsbakk
2026-06-03 23:49 ` Junio C Hamano
2026-06-03 16:14 ` [PATCH v2 5/9] reset: introduce ability to skip reference updates Patrick Steinhardt
2026-06-03 23:51 ` Junio C Hamano
2026-06-04 9:01 ` Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 6/9] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 7/9] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 8/9] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 9/9] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-03 19:04 ` Kristoffer Haugsbakk
2026-06-04 9:02 ` Patrick Steinhardt
2026-06-03 23:58 ` Junio C Hamano
2026-06-04 9:02 ` Patrick Steinhardt [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=aiE_FtbkLVjXdSVX@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pabloosabaterr@gmail.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