cherry-pick/revert: advise using --skip

The previous commit introduced a --skip flag for cherry-pick and revert. Update the advice messages, to tell users about this less cumbersome way of skipping commits. Also add tests to ensure everything is working fine. Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rohit Ashiwal committed Jul 2, 2019 at 14:41 UTC dcb500dc16ce8db556b51e9a5b3fa977111d0443
3 files changed +34 -8
builtin/commit.c
+8 -5
@@ -60,15 +60,18 @@ N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\
60 "\n");
61
62 static const char empty_cherry_pick_advice_single[] =
63 -N_("Otherwise, please use 'git reset'\n");
63 +N_("Otherwise, please use 'git cherry-pick --skip'\n");
64
65 static const char empty_cherry_pick_advice_multi[] =
66 -N_("If you wish to skip this commit, use:\n"
66 +N_("and then use:\n"
67 "\n"
68 -" git reset\n"
68 +" git cherry-pick --continue\n"
69 "\n"
70 -"Then \"git cherry-pick --continue\" will resume cherry-picking\n"
71 -"the remaining commits.\n");
70 +"to resume cherry-picking the remaining commits.\n"
71 +"If you wish to skip this commit, use:\n"
72 +"\n"
73 +" git cherry-pick --skip\n"
74 +"\n");
75
76 static const char *color_status_slots[] = {
77 [WT_STATUS_HEADER] = "header",
sequencer.c
+6 -3
@@ -2655,18 +2655,20 @@ static int create_seq_dir(struct repository *r)
2655 enum replay_action action;
2656 const char *in_progress_error = NULL;
2657 const char *in_progress_advice = NULL;
2658 + unsigned int advise_skip = file_exists(git_path_revert_head(r)) ||
2659 + file_exists(git_path_cherry_pick_head(r));
2660
2661 if (!sequencer_get_last_command(r, &action)) {
2662 switch (action) {
2663 case REPLAY_REVERT:
2664 in_progress_error = _("revert is already in progress");
2665 in_progress_advice =
2664 - _("try \"git revert (--continue | --abort | --quit)\"");
2666 + _("try \"git revert (--continue | %s--abort | --quit)\"");
2667 break;
2668 case REPLAY_PICK:
2669 in_progress_error = _("cherry-pick is already in progress");
2670 in_progress_advice =
2669 - _("try \"git cherry-pick (--continue | --abort | --quit)\"");
2671 + _("try \"git cherry-pick (--continue | %s--abort | --quit)\"");
2672 break;
2673 default:
2674 BUG("unexpected action in create_seq_dir");
@@ -2675,7 +2677,8 @@ static int create_seq_dir(struct repository *r)
2677 if (in_progress_error) {
2678 error("%s", in_progress_error);
2679 if (advice_sequencer_in_use)
2678 - advise("%s", in_progress_advice);
2680 + advise(in_progress_advice,
2681 + advise_skip ? "--skip | " : "");
2682 return -1;
2683 }
2684 if (mkdir(git_path_seq_dir(), 0777) < 0)
t/t3510-cherry-pick-sequence.sh
+20
@@ -172,6 +172,26 @@ test_expect_success 'check advice when we move HEAD by committing' '
172 test_i18ncmp expect advice
173 '
174
175 +test_expect_success 'selectively advise --skip while launching another sequence' '
176 + pristine_detach initial &&
177 + cat >expect <<-EOF &&
178 + error: cherry-pick is already in progress
179 + hint: try "git cherry-pick (--continue | --skip | --abort | --quit)"
180 + fatal: cherry-pick failed
181 + EOF
182 + test_must_fail git cherry-pick picked..yetanotherpick &&
183 + test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
184 + test_i18ncmp expect advice &&
185 + cat >expect <<-EOF &&
186 + error: cherry-pick is already in progress
187 + hint: try "git cherry-pick (--continue | --abort | --quit)"
188 + fatal: cherry-pick failed
189 + EOF
190 + git reset --merge &&
191 + test_must_fail git cherry-pick picked..yetanotherpick 2>advice &&
192 + test_i18ncmp expect advice
193 +'
194 +
195 test_expect_success 'allow skipping commit but not abort for a new history' '
196 pristine_detach initial &&
197 cat >expect <<-EOF &&