builtin-am: exit with user friendly message on failure
Since ced9456 (Give the user a hint for how to continue in the case that git-am fails because it requires user intervention, 2006-05-02), git-am prints additional information on how the user can re-invoke git-am to resume patch application after resolving the failure. Re-implement this through the die_user_resolve() function. Since cc12005 (Make git rebase interactive help match documentation., 2006-05-13), git-am supports the --resolvemsg option which is used by git-rebase to override the message printed out when git-am fails. Re-implement this option. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paul Tan committed
Aug 4, 2015 at 21:51 UTC
2d83109aabbb8c660c27cbf03ec67cb88822639f
1 file changed
+26
-4
builtin/am.c
+26
-4
@@ -83,6 +83,7 @@ struct am_state {
83
84
/* various operating modes and command line options */
85
int quiet;
86
+ const char *resolvemsg;
87
};
88
89
/**
@@ -646,6 +647,25 @@ static int index_has_changes(struct strbuf *sb)
647
}
648
}
649
650
+/**
651
+ * Dies with a user-friendly message on how to proceed after resolving the
652
+ * problem. This message can be overridden with state->resolvemsg.
653
+ */
654
+static void NORETURN die_user_resolve(const struct am_state *state)
655
+{
656
+ if (state->resolvemsg) {
657
+ printf_ln("%s", state->resolvemsg);
658
+ } else {
659
+ const char *cmdline = "git am";
660
+
661
+ printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline);
662
+ printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline);
663
+ printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
664
+ }
665
+
666
+ exit(128);
667
+}
668
+
669
/**
670
* Parses `mail` using git-mailinfo, extracting its patch and authorship info.
671
* state->msg will be set to the patch message. state->author_name,
@@ -706,7 +726,7 @@ static int parse_mail(struct am_state *state, const char *mail)
726
727
if (is_empty_file(am_path(state, "patch"))) {
728
printf_ln(_("Patch is empty. Was it split wrong?"));
709
- exit(128);
729
+ die_user_resolve(state);
730
}
731
732
strbuf_addstr(&msg, "\n\n");
@@ -871,7 +891,7 @@ static void am_run(struct am_state *state, int resume)
891
printf_ln(_("The copy of the patch that failed is found in: %s"),
892
am_path(state, "patch"));
893
874
- exit(128);
894
+ die_user_resolve(state);
895
}
896
897
do_commit(state);
@@ -899,13 +919,13 @@ static void am_resolve(struct am_state *state)
919
printf_ln(_("No changes - did you forget to use 'git add'?\n"
920
"If there is nothing left to stage, chances are that something else\n"
921
"already introduced the same changes; you might want to skip this patch."));
902
- exit(128);
922
+ die_user_resolve(state);
923
}
924
925
if (unmerged_cache()) {
926
printf_ln(_("You still have unmerged paths in your index.\n"
927
"Did you forget to use 'git add'?"));
908
- exit(128);
928
+ die_user_resolve(state);
929
}
930
931
do_commit(state);
@@ -1133,6 +1153,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1153
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
1154
N_("format the patch(es) are in"),
1155
parse_opt_patchformat),
1156
+ OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
1157
+ N_("override error message when patch failure occurs")),
1158
OPT_CMDMODE(0, "continue", &resume,
1159
N_("continue applying patches after resolving a conflict"),
1160
RESUME_RESOLVED),