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>
This commit is contained in:
Paul Tan 2015-08-04 21:51:56 +08:00 committed by Junio C Hamano
parent 88b291fe9d
commit b8803d8f8c

View File

@ -455,6 +455,27 @@ static void am_destroy(const struct am_state *state)
strbuf_release(&sb);
}
/**
* Runs applypatch-msg hook. Returns its exit code.
*/
static int run_applypatch_msg_hook(struct am_state *state)
{
int ret;
assert(state->msg);
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
if (!ret) {
free(state->msg);
state->msg = NULL;
if (read_commit_msg(state) < 0)
die(_("'%s' was deleted by the applypatch-msg hook"),
am_path(state, "final-commit"));
}
return ret;
}
/**
* Runs post-rewrite hook. Returns it exit code.
*/
@ -1420,6 +1441,9 @@ static void am_run(struct am_state *state, int resume)
write_commit_msg(state);
}
if (run_applypatch_msg_hook(state))
exit(1);
say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
apply_status = run_apply(state, NULL);