builtin-am: invoke applypatch-msg hook

Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am.sh will invoke the applypatch-msg hooks just after extracting the patch message. If the applypatch-msg hook exits with a non-zero status, git-am.sh abort before even applying the patch to the index. Re-implement this in builtin/am.c. 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 b8803d8f8c987b9867385a033aab71a7cb967553
1 file changed +24
builtin/am.c
+24
@@ -455,6 +455,27 @@ static void am_destroy(const struct am_state *state)
455 strbuf_release(&sb);
456 }
457
458 +/**
459 + * Runs applypatch-msg hook. Returns its exit code.
460 + */
461 +static int run_applypatch_msg_hook(struct am_state *state)
462 +{
463 + int ret;
464 +
465 + assert(state->msg);
466 + ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
467 +
468 + if (!ret) {
469 + free(state->msg);
470 + state->msg = NULL;
471 + if (read_commit_msg(state) < 0)
472 + die(_("'%s' was deleted by the applypatch-msg hook"),
473 + am_path(state, "final-commit"));
474 + }
475 +
476 + return ret;
477 +}
478 +
479 /**
480 * Runs post-rewrite hook. Returns it exit code.
481 */
@@ -1420,6 +1441,9 @@ static void am_run(struct am_state *state, int resume)
1441 write_commit_msg(state);
1442 }
1443
1444 + if (run_applypatch_msg_hook(state))
1445 + exit(1);
1446 +
1447 say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
1448
1449 apply_status = run_apply(state, NULL);