Re: [PATCH 4/4] cherry-pick: Add `--empty` for more robust redundant commit handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[+cc Junio]

On Tue, Jan 23, 2024 at 8:25 AM Phillip Wood <phillip.wood123@xxxxxxxxx> wrote:
>
> Hi Brian
>
>
> On 19/01/2024 05:59, brianmlyles@xxxxxxxxx wrote:
>
> > The `--keep-redundant-commits` option will be documented as a deprecated
> > synonym of `--empty=keep`, and will be supported for backwards
> > compatibility for the time being.
>
> I'm not sure if we need to deprecate it as in "it will be removed in the
> future" or just reduce it prominence in favor of --empty

This is also related to Junio's comment:

> On Tue, Jan 23, 2024 at 12:01 PM Junio C Hamano <gitster@xxxxxxxxx>
wrote:
>
> True, especially since --empty=keep is much less descriptive and the
> part after "note that ..." below will take a long time before
> sticking in readers' brain.

My primary motivation here was simply for consistency with `--empty` for
both git-rebase(1) and git-am(1). In theory, I am not opposed to
updating this patch to instead simply add a `--drop-redundant-commits`
option if we feel that provides better usability. However, I think that
the consistency would be better.

I will happily defer to the group consensus here, with the options I see
being:

1. No deprecation: just make `--keep-redundant-commits` a synonym of
  `--empty=keep`
2. Soft deprecation: Give a warning when `--keep-redundant-commits` is
  used
3. Add `--drop-redundant-commits` instead of `--empty`

My preference would be 2, followed by 1 and then 3.

> I'm still on the fence about "stop" vs "ask". I see in your tests you've
> accidentally used "ask" which makes me wonder if that is the more
> familiar term for users who probably use "git rebase" more often than
> "git am".

Oh, thank you for catching that. The cause here was actually because I
had initially written these tests prior to adding the "ask -> stop"
change rather than familiarity. I simply failed to update the tests
after moving things around.

> The code changes look good but I think we want to update
> verify_opt_compatible() to check for "--empty" being combined with
> "--continue" etc. as well.

It looks like `--keep-redundant-commits` was not being included in these
checks previously. I suspect that to be an oversight though.

I can add this for v2.

>
> >       if (cleanup_arg) {
> >               opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1);
> >               opts->explicit_cleanup = 1;
> > diff --git a/sequencer.c b/sequencer.c
> > index 582bde8d46..c49c27c795 100644
> > --- a/sequencer.c
> > +++ b/sequencer.c
> > @@ -2934,6 +2934,9 @@ static int populate_opts_cb(const char *key, const char *value,
> >       else if (!strcmp(key, "options.allow-empty-message"))
> >               opts->allow_empty_message =
> >                       git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
> > +     else if (!strcmp(key, "options.drop-redundant-commits"))
> > +             opts->drop_redundant_commits =
> > +                     git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
> >       else if (!strcmp(key, "options.keep-redundant-commits"))
> >               opts->keep_redundant_commits =
> >                       git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
> > @@ -3478,6 +3481,9 @@ static int save_opts(struct replay_opts *opts)
> >       if (opts->allow_empty_message)
> >               res |= git_config_set_in_file_gently(opts_file,
> >                               "options.allow-empty-message", "true");
> > +     if (opts->drop_redundant_commits)
> > +             res |= git_config_set_in_file_gently(opts_file,
> > +                             "options.drop-redundant-commits", "true");
>
> It is good that we're saving the option - it would be good to add a test
> to check that we remember --empty after stopping for a conflict resolution.

I can add a test for this in v2

> >       if (opts->keep_redundant_commits)
> >               res |= git_config_set_in_file_gently(opts_file,
> >                               "options.keep-redundant-commits", "true");
> > diff --git a/t/t3505-cherry-pick-empty.sh b/t/t3505-cherry-pick-empty.sh
> > index 6adfd25351..ae0cf7886a 100755
> > --- a/t/t3505-cherry-pick-empty.sh
> > +++ b/t/t3505-cherry-pick-empty.sh
> > @@ -89,7 +89,7 @@ test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
> >       git commit -m "add file2 on the side"
> >   '
> >
> > -test_expect_success 'cherry-pick a no-op without --keep-redundant' '
> > +test_expect_success 'cherry-pick a no-op with neither --keep-redundant nor --empty' '
> >       git reset --hard &&
> >       git checkout fork^0 &&
> >       test_must_fail git cherry-pick main
> > @@ -104,4 +104,28 @@ test_expect_success 'cherry-pick a no-op with --keep-redundant' '
> >       test_cmp expect actual
> >   '
> >
> > +test_expect_success 'cherry-pick a no-op with --empty=ask' '
> > +     git reset --hard &&
> > +     git checkout fork^0 &&
> > +     test_must_fail git cherry-pick --empty=ask main
>
> This is an example of why it is a good idea to check the error message
> when using "test_must_fail" as here the test will fail due to a bad
> value passed to "--empty" rather than for the reason we want the test to
> check. It would be good to add a separate test to check that we reject
> invalid "--empty" values.

An excellent catch, thank you. Will be addressed in v2

> > +'
> > +
> > +test_expect_success 'cherry-pick a no-op with --empty=drop' '
> > +     git reset --hard &&
> > +     git checkout fork^0 &&
> > +     git cherry-pick --empty=drop main &&
> > +     git show -s --format=%s >actual &&
> > +     echo "add file2 on the side" >expect &&
> > +     test_cmp expect actual
>
> I think you could simplify this by using test_commit_message

Thanks for pointing that function out -- you're absolutely right. Will
be addressed in v2.


Thanks for the review,
Brian Lyles





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux