Re: [PATCH v2] cherry-pick: refuse cherry-pick sequence if index is dirty
- From
Tao Klerks <tao@klerks.biz>
- Date
- Sep 6, 2023, 05:02 UTC
- Message-ID
- <CAPMMpoj8udDuDferkaRfoKDV6EHMVO6fH3_GE9SUN51VKbwvJA@mail.gmail.com>
- In-Reply-To
- <999f12b2-38d6-f446-e763-4985116ad37d@gmail.com>
On Tue, May 30, 2023 at 4:16 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 13 quoted lines
> > Hi Tao > > On 28/05/2023 10:08, Tao Klerks via GitGitGadget wrote: > > From: Tao Klerks <tao@klerks.biz> > > > <SNIP> > > I found the changes up to this point a bit confusing. Maybe I've missed > something but I don't think they are really related to fixing the bug > described in the commit message. As such they're a distraction from the > "real" fix. >
Understood, thanks - *if* I kept them, they should be in a separate "prep refactor" commit.
The reason I did all this was just that I needed to build a new message that displayed the correct cherry-pick action name - something that was, in the existing code, done by repeating the entire advice message. I didn't want to do the same, and if I was going add what I needed to construct the message more dynamically I figured I should update the existing repetition-based approach.
Show 5 quoted lines
> > > + requested_action_name = cherry_pick_action_name(requested_action); > > We already have the function action_name() so I don't think we need to > add cherry_pick_action_name().
The reason I had added a new one was that action_name() also supported "REPLAY_INTERACTIVE_REBASE", which should not be an option in the codepath that I was refactoring. I wanted to retain the existing "defensiveness", but that clearly got in the way of both brevity and clarity.
> Also the name of the new function is > confusing as it may return "revert".
Yeah, the name was supposed to reflect the context ("cherry-pick logic which also covers revert, as opposed to rebase which also uses sequencer but is a substantially separate flow"), rather than the output value.
Show 36 quoted lines
>
> > + if (require_clean_index(r, requested_action_name,
> > + _("Please commit or stash them."), 1, 1))
>
> How does this interact with "--no-commit"? I think the check that you
> refer to in the commit message is in do_pick_commit() where we have
>
> if (opts->no_commit) {
> /*
> * We do not intend to commit immediately. We just want to
> * merge the differences in, so let's compute the tree
> * that represents the "current" state for the merge machinery
> * to work on.
> */
> if (write_index_as_tree(&head, r->index, r->index_file, 0, NULL))
> return error(_("your index file is unmerged."));
> } else {
> unborn = repo_get_oid(r, "HEAD", &head);
> /* Do we want to generate a root commit? */
> if (is_pick_or_similar(command) && opts->have_squash_onto &&
> oideq(&head, &opts->squash_onto)) {
> if (is_fixup(command))
> return error(_("cannot fixup root commit"));
> flags |= CREATE_ROOT_COMMIT;
> unborn = 1;
> } else if (unborn)
> oidcpy(&head, the_hash_algo->empty_tree);
> if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
> NULL, 0))
> return error_dirty_index(r, opts);
> }
>
> I think it would be simpler to reuse the existing check by extracting
> the "else" clause above into a separate function in sequencer.c and call
> it here guarded by "if (!opts->no_commit)" as well as in that "else"
> clause in do_pick_commit()That sounds very plausible.
I will (very belatedly) have a go, and submit another version sometime soon.
Thanks so much for taking the time to review, and my apologies for the months-later context revival!