Skip to content

Commit b8803d8

Browse files
pyokagangitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88b291f commit b8803d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

builtin/am.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,27 @@ static void am_destroy(const struct am_state *state)
455455
strbuf_release(&sb);
456456
}
457457

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+
458479
/**
459480
* Runs post-rewrite hook. Returns it exit code.
460481
*/
@@ -1420,6 +1441,9 @@ static void am_run(struct am_state *state, int resume)
14201441
write_commit_msg(state);
14211442
}
14221443

1444+
if (run_applypatch_msg_hook(state))
1445+
exit(1);
1446+
14231447
say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
14241448

14251449
apply_status = run_apply(state, NULL);

0 commit comments

Comments
 (0)