Skip to content

Commit 2d83109

Browse files
pyokagangitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d28cf7 commit 2d83109

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

builtin/am.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct am_state {
8383

8484
/* various operating modes and command line options */
8585
int quiet;
86+
const char *resolvemsg;
8687
};
8788

8889
/**
@@ -646,6 +647,25 @@ static int index_has_changes(struct strbuf *sb)
646647
}
647648
}
648649

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+
649669
/**
650670
* Parses `mail` using git-mailinfo, extracting its patch and authorship info.
651671
* 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)
706726

707727
if (is_empty_file(am_path(state, "patch"))) {
708728
printf_ln(_("Patch is empty. Was it split wrong?"));
709-
exit(128);
729+
die_user_resolve(state);
710730
}
711731

712732
strbuf_addstr(&msg, "\n\n");
@@ -871,7 +891,7 @@ static void am_run(struct am_state *state, int resume)
871891
printf_ln(_("The copy of the patch that failed is found in: %s"),
872892
am_path(state, "patch"));
873893

874-
exit(128);
894+
die_user_resolve(state);
875895
}
876896

877897
do_commit(state);
@@ -899,13 +919,13 @@ static void am_resolve(struct am_state *state)
899919
printf_ln(_("No changes - did you forget to use 'git add'?\n"
900920
"If there is nothing left to stage, chances are that something else\n"
901921
"already introduced the same changes; you might want to skip this patch."));
902-
exit(128);
922+
die_user_resolve(state);
903923
}
904924

905925
if (unmerged_cache()) {
906926
printf_ln(_("You still have unmerged paths in your index.\n"
907927
"Did you forget to use 'git add'?"));
908-
exit(128);
928+
die_user_resolve(state);
909929
}
910930

911931
do_commit(state);
@@ -1133,6 +1153,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
11331153
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
11341154
N_("format the patch(es) are in"),
11351155
parse_opt_patchformat),
1156+
OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
1157+
N_("override error message when patch failure occurs")),
11361158
OPT_CMDMODE(0, "continue", &resume,
11371159
N_("continue applying patches after resolving a conflict"),
11381160
RESUME_RESOLVED),

0 commit comments

Comments
 (0)