Skip to content

Commit 566902f

Browse files
thierryredinggitster
authored andcommitted
am: allow passing --no-verify flag
The git-am --no-verify flag is analogous to the same flag passed to git-commit. It bypasses the pre-applypatch and applypatch-msg hooks if they are enabled. Signed-off-by: Thierry Reding <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eea7033 commit 566902f

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

Documentation/git-am.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
12+
'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--no-verify]
1313
[--[no-]3way] [--interactive] [--committer-date-is-author-date]
1414
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
1515
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -138,6 +138,12 @@ include::rerere-options.txt[]
138138
--interactive::
139139
Run interactively.
140140

141+
-n::
142+
--no-verify::
143+
By default, the pre-applypatch and applypatch-msg hooks are run.
144+
When any of `--no-verify` or `-n` is given, these are bypassed.
145+
See also linkgit:githooks[5].
146+
141147
--committer-date-is-author-date::
142148
By default the command records the date from the e-mail
143149
message as the commit author date, and uses the time of

builtin/am.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct am_state {
117117

118118
/* various operating modes and command line options */
119119
int interactive;
120+
int no_verify;
120121
int threeway;
121122
int quiet;
122123
int signoff; /* enum signoff_type */
@@ -472,10 +473,12 @@ static void am_destroy(const struct am_state *state)
472473
*/
473474
static int run_applypatch_msg_hook(struct am_state *state)
474475
{
475-
int ret;
476+
int ret = 0;
476477

477478
assert(state->msg);
478-
ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
479+
480+
if (!state->no_verify)
481+
ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
479482

480483
if (!ret) {
481484
FREE_AND_NULL(state->msg);
@@ -1640,7 +1643,7 @@ static void do_commit(const struct am_state *state)
16401643
const char *reflog_msg, *author, *committer = NULL;
16411644
struct strbuf sb = STRBUF_INIT;
16421645

1643-
if (run_hooks("pre-applypatch"))
1646+
if (!state->no_verify && run_hooks("pre-applypatch"))
16441647
exit(1);
16451648

16461649
if (write_cache_as_tree(&tree, 0, NULL))
@@ -2329,6 +2332,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23292332
struct option options[] = {
23302333
OPT_BOOL('i', "interactive", &state.interactive,
23312334
N_("run interactively")),
2335+
OPT_BOOL('n', "no-verify", &state.no_verify,
2336+
N_("bypass pre-applypatch and applypatch-msg hooks")),
23322337
OPT_HIDDEN_BOOL('b', "binary", &binary,
23332338
N_("historical option -- no-op")),
23342339
OPT_BOOL('3', "3way", &state.threeway,

t/t4150-am.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ test_expect_success 'am with failing applypatch-msg hook' '
345345
test_cmp_rev first HEAD
346346
'
347347

348+
test_expect_success 'am with failing applypatch-msg hook (no verify)' '
349+
rm -fr .git/rebase-apply &&
350+
git reset --hard &&
351+
git checkout first &&
352+
test_hook applypatch-msg <<-\EOF &&
353+
echo hook-message >"$1"
354+
exit 1
355+
EOF
356+
git am --no-verify patch1 &&
357+
test_path_is_missing .git/rebase-apply &&
358+
git diff --exit-code second &&
359+
git log -1 --format=format:%B >actual &&
360+
test_cmp msg actual
361+
'
362+
348363
test_expect_success 'am with pre-applypatch hook' '
349364
rm -fr .git/rebase-apply &&
350365
git reset --hard &&
@@ -374,6 +389,23 @@ test_expect_success 'am with failing pre-applypatch hook' '
374389
test_cmp_rev first HEAD
375390
'
376391

392+
test_expect_success 'am with failing pre-applypatch hook (no verify)' '
393+
rm -fr .git/rebase-apply &&
394+
git reset --hard &&
395+
git checkout first &&
396+
touch empty-file &&
397+
test_hook pre-applypatch <<-\EOF &&
398+
rm empty-file
399+
exit 1
400+
EOF
401+
git am --no-verify patch1 &&
402+
test_path_is_missing .git/rebase-apply &&
403+
test_path_is_file empty-file &&
404+
git diff --exit-code second &&
405+
git log -1 --format=format:%B >actual &&
406+
test_cmp msg actual
407+
'
408+
377409
test_expect_success 'am with post-applypatch hook' '
378410
rm -fr .git/rebase-apply &&
379411
git reset --hard &&

0 commit comments

Comments
 (0)