{"thread":{"id":"58813","subject":"[PATCH] am: Allow passing --no-verify flag","startedAt":"2022-11-18T13:27:56Z","lastAt":"2022-11-19T01:43:09Z","messageCount":3,"participants":["Thierry Reding","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"467519","messageId":"20221118132743.3525725-1-thierry.reding@gmail.com","threadId":"58813","inReplyTo":null,"subject":"[PATCH] am: Allow passing --no-verify flag","fromName":"Thierry Reding","fromEmail":"thierry.reding@gmail.com","sentAt":"2022-11-18T13:27:43Z","receivedAt":"2022-11-18T13:27:56Z","isPatch":true,"sender":{"key":"thierry.reding@gmail.com","avatar":null},"body":"From: Thierry Reding <treding@nvidia.com>\n\nThe git-am --no-verify flag is analogous to the same flag passed to\ngit-commit. It bypasses the pre-applypatch and applypatch-msg hooks\nif they are enabled.\n\nSigned-off-by: Thierry Reding <treding@nvidia.com>\n---\n Documentation/git-am.txt |  8 +++++++-\n builtin/am.c             | 11 ++++++++---\n 2 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 326276e51ce5..0c1dfb3c98b4 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox\n SYNOPSIS\n --------\n [verse]\n-'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]\n+'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--no-verify]\n \t [--[no-]3way] [--interactive] [--committer-date-is-author-date]\n \t [--ignore-date] [--ignore-space-change | --ignore-whitespace]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n@@ -138,6 +138,12 @@ include::rerere-options.txt[]\n --interactive::\n \tRun interactively.\n \n+-n::\n+--no-verify::\n+\tBy default, the pre-applypatch and applypatch-msg hooks are run.\n+\tWhen any of `--no-verify` or `-n` is given, these are bypassed.\n+\tSee also linkgit:githooks[5].\n+\n --committer-date-is-author-date::\n \tBy default the command records the date from the e-mail\n \tmessage as the commit author date, and uses the time of\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 20aea0d2487b..26ad8a468dc4 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -117,6 +117,7 @@ struct am_state {\n \n \t/* various operating modes and command line options */\n \tint interactive;\n+\tint no_verify;\n \tint threeway;\n \tint quiet;\n \tint signoff; /* enum signoff_type */\n@@ -472,10 +473,12 @@ static void am_destroy(const struct am_state *state)\n  */\n static int run_applypatch_msg_hook(struct am_state *state)\n {\n-\tint ret;\n+\tint ret = 0;\n \n \tassert(state->msg);\n-\tret = run_hooks_l(\"applypatch-msg\", am_path(state, \"final-commit\"), NULL);\n+\n+\tif (!state->no_verify)\n+\t\tret = run_hooks_l(\"applypatch-msg\", am_path(state, \"final-commit\"), NULL);\n \n \tif (!ret) {\n \t\tFREE_AND_NULL(state->msg);\n@@ -1640,7 +1643,7 @@ static void do_commit(const struct am_state *state)\n \tconst char *reflog_msg, *author, *committer = NULL;\n \tstruct strbuf sb = STRBUF_INIT;\n \n-\tif (run_hooks(\"pre-applypatch\"))\n+\tif (!state->no_verify && run_hooks(\"pre-applypatch\"))\n \t\texit(1);\n \n \tif (write_cache_as_tree(&tree, 0, NULL))\n@@ -2329,6 +2332,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \tstruct option options[] = {\n \t\tOPT_BOOL('i', \"interactive\", &state.interactive,\n \t\t\tN_(\"run interactively\")),\n+\t\tOPT_BOOL('n', \"no-verify\", &state.no_verify,\n+\t\t\tN_(\"bypass pre-applypatch and applypatch-msg hooks\")),\n \t\tOPT_HIDDEN_BOOL('b', \"binary\", &binary,\n \t\t\tN_(\"historical option -- no-op\")),\n \t\tOPT_BOOL('3', \"3way\", &state.threeway,\n-- \n2.38.1\n\n"},{"id":"467527","messageId":"Y3fNQ9ysAeOsyOSQ@nand.local","threadId":"58813","inReplyTo":"20221118132743.3525725-1-thierry.reding@gmail.com","subject":"Re: [PATCH] am: Allow passing --no-verify flag","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-18T18:21:55Z","receivedAt":"2022-11-18T18:22:23Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Nov 18, 2022 at 02:27:43PM +0100, Thierry Reding wrote:\n> From: Thierry Reding <treding@nvidia.com>\n>\n> The git-am --no-verify flag is analogous to the same flag passed to\n> git-commit. It bypasses the pre-applypatch and applypatch-msg hooks\n> if they are enabled.\n\nThe patch below looks reasonable to me. Is there a way that we could\ntest this easily? It looks trivially correct to my eyes, but I want to\navoid the possibility of regressing here in the future.\n\nThanks,\nTaylor\n"},{"id":"467547","messageId":"Y3goBHxEd8xUE4Bc@orome","threadId":"58813","inReplyTo":"Y3fNQ9ysAeOsyOSQ@nand.local","subject":"Re: [PATCH] am: Allow passing --no-verify flag","fromName":"Thierry Reding","fromEmail":"thierry.reding@gmail.com","sentAt":"2022-11-19T00:49:08Z","receivedAt":"2022-11-19T01:43:09Z","isPatch":true,"sender":{"key":"thierry.reding@gmail.com","avatar":null},"body":"On Fri, Nov 18, 2022 at 01:21:55PM -0500, Taylor Blau wrote:\n> On Fri, Nov 18, 2022 at 02:27:43PM +0100, Thierry Reding wrote:\n> > From: Thierry Reding <treding@nvidia.com>\n> >\n> > The git-am --no-verify flag is analogous to the same flag passed to\n> > git-commit. It bypasses the pre-applypatch and applypatch-msg hooks\n> > if they are enabled.\n> \n> The patch below looks reasonable to me. Is there a way that we could\n> test this easily? It looks trivially correct to my eyes, but I want to\n> avoid the possibility of regressing here in the future.\n\nYeah, turns out this can be pretty easily checked. I'll resend a v2 with\nthe test included.\n\nThierry\n"}]}