sequencer: add advice for revert

In the case of merge conflicts, while performing a revert, we are currently advised to use `git cherry-pick --<sequencer-options>`. Introduce a separate advice message for `git revert`. Also change the signature of `create_seq_dir` to handle which advice to display selectively. 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 6a1f9046a40ad69eb00e5a83c6825972113f6e0f
4 files changed +34 -6
Documentation/config/advice.txt
+2
@@ -57,6 +57,8 @@ advice.*::
57 resolveConflict::
58 Advice shown by various commands when conflicts
59 prevent the operation from being performed.
60 + sequencerInUse::
61 + Advice shown when a sequencer command is already in progress.
62 implicitIdentity::
63 Advice on how to set your identity configuration when
64 your information is guessed from the system username and
advice.c
+2
@@ -15,6 +15,7 @@ int advice_status_u_option = 1;
15 int advice_commit_before_merge = 1;
16 int advice_reset_quiet_warning = 1;
17 int advice_resolve_conflict = 1;
18 +int advice_sequencer_in_use = 1;
19 int advice_implicit_identity = 1;
20 int advice_detached_head = 1;
21 int advice_set_upstream_failure = 1;
@@ -71,6 +72,7 @@ static struct {
72 { "commitBeforeMerge", &advice_commit_before_merge },
73 { "resetQuiet", &advice_reset_quiet_warning },
74 { "resolveConflict", &advice_resolve_conflict },
75 + { "sequencerInUse", &advice_sequencer_in_use },
76 { "implicitIdentity", &advice_implicit_identity },
77 { "detachedHead", &advice_detached_head },
78 { "setupStreamFailure", &advice_set_upstream_failure },
advice.h
+1
@@ -15,6 +15,7 @@ extern int advice_status_u_option;
15 extern int advice_commit_before_merge;
16 extern int advice_reset_quiet_warning;
17 extern int advice_resolve_conflict;
18 +extern int advice_sequencer_in_use;
19 extern int advice_implicit_identity;
20 extern int advice_detached_head;
21 extern int advice_set_upstream_failure;
sequencer.c
+29 -6
@@ -2650,15 +2650,38 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
2650 return 0;
2651 }
2652
2653 -static int create_seq_dir(void)
2653 +static int create_seq_dir(struct repository *r)
2654 {
2655 - if (file_exists(git_path_seq_dir())) {
2656 - error(_("a cherry-pick or revert is already in progress"));
2657 - advise(_("try \"git cherry-pick (--continue | --quit | --abort)\""));
2655 + enum replay_action action;
2656 + const char *in_progress_error = NULL;
2657 + const char *in_progress_advice = NULL;
2658 +
2659 + if (!sequencer_get_last_command(r, &action)) {
2660 + switch (action) {
2661 + case REPLAY_REVERT:
2662 + in_progress_error = _("revert is already in progress");
2663 + in_progress_advice =
2664 + _("try \"git revert (--continue | --abort | --quit)\"");
2665 + break;
2666 + case REPLAY_PICK:
2667 + in_progress_error = _("cherry-pick is already in progress");
2668 + in_progress_advice =
2669 + _("try \"git cherry-pick (--continue | --abort | --quit)\"");
2670 + break;
2671 + default:
2672 + BUG("unexpected action in create_seq_dir");
2673 + }
2674 + }
2675 + if (in_progress_error) {
2676 + error("%s", in_progress_error);
2677 + if (advice_sequencer_in_use)
2678 + advise("%s", in_progress_advice);
2679 return -1;
2659 - } else if (mkdir(git_path_seq_dir(), 0777) < 0)
2680 + }
2681 + if (mkdir(git_path_seq_dir(), 0777) < 0)
2682 return error_errno(_("could not create sequencer directory '%s'"),
2683 git_path_seq_dir());
2684 +
2685 return 0;
2686 }
2687
@@ -4242,7 +4265,7 @@ int sequencer_pick_revisions(struct repository *r,
4265 */
4266
4267 if (walk_revs_populate_todo(&todo_list, opts) ||
4245 - create_seq_dir() < 0)
4268 + create_seq_dir(r) < 0)
4269 return -1;
4270 if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
4271 return error(_("can't revert as initial commit"));