am: Allow passing --no-verify flag
PATCH v2 1/1 am: Allow passing --no-verify flag
From: Thierry Reding <[email protected]>
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.
---
Changes in v2:
- add test to verify that the new option works
Documentation/git-am.txt | 8 +++++- builtin/am.c | 11 ++++++-- t/t4154-am-noverify.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100755 t/t4154-am-noverify.sh
Documentation/git-am.txt +7 -1
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox SYNOPSIS -------- [verse] -'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] +'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--no-verify] [--[no-]3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -138,6 +138,12 @@ include::rerere-options.txt[] --interactive:: Run interactively. +-n:: +--no-verify:: + By default, the pre-applypatch and applypatch-msg hooks are run. + When any of `--no-verify` or `-n` is given, these are bypassed. + See also linkgit:githooks[5]. + --committer-date-is-author-date:: By default the command records the date from the e-mail message as the commit author date, and uses the time of
builtin/am.c +8 -3
@@ -117,6 +117,7 @@ struct am_state {/* various operating modes and command line options */ int interactive; +int no_verify;int threeway;int quiet;int signoff;/* enum signoff_type */
@@ -472,10 +473,12 @@ static void am_destroy(const struct am_state *state)*/ static int run_applypatch_msg_hook (struct am_state *state) { -int ret; +int ret =0 ;assert (state->msg); - ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL ); + +if (!state->no_verify) + ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL );if (!ret) {FREE_AND_NULL (state->msg);
@@ -1640,7 +1643,7 @@ static void do_commit(const struct am_state *state)const char *reflog_msg, *author, *committer =NULL ;struct strbuf sb =STRBUF_INIT ; -if (run_hooks ("pre-applypatch" )) +if (!state->no_verify &&run_hooks ("pre-applypatch" ))exit (1 );if (write_cache_as_tree (&tree,0 ,NULL ))
@@ -2329,6 +2332,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)struct option options[] = {OPT_BOOL ('i' ,"interactive" , &state.interactive,N_ ("run interactively" )), +OPT_BOOL ('n' ,"no-verify" , &state.no_verify, +N_ ("bypass pre-applypatch and applypatch-msg hooks" )),OPT_HIDDEN_BOOL ('b' ,"binary" , &binary,N_ ("historical option -- no-op" )), OPT_BOOL('3', "3way", &state.threeway,
t/t4154-am-noverify.sh new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.38.1
Quoted 13 lines · Thierry Reding
From: Thierry Reding <[email protected]>
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]>---
Changes in v2:
- add test to verify that the new option works+-n:: +--no-verify::
Documentation/git-am.txt include::rerere-options.txt[] · line 145
Quoted 3 lines
Documentation/git-am.txt +3
-0+ By default, the pre-applypatch and applypatch-msg hooks are run. + When any of `--no-verify` or `-n` is given, these are bypassed. + See also linkgit:githooks[5].
I think the goal of this topic is to allow bypassing the checks made by these two hooks (and possibly future ones that validate the input to "am"), and there are at least two possible implementations to achieve that goal. You can still run the hook and ignore its failure exit, or you can skip running the hook and pretend as if hook succeeded.
As it is documented that applypatch-msg is allowed to edit the message file to normalize the message, between the two, running the hook (to allow the hook to automatically edit the message) but ignoring its failure would be a more intuitive approach to "bypass" the check. If the option were called --no-hook or --bypass-hooks then it would be a different story, though.
builtin/am.c static void am_destroy(const struct am_state *state) · line 481
Quoted 5 lines
builtin/am.c +3
-1assert (state->msg); - ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL ); + +if (!state->no_verify) + ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL );
And it seems that this took a less intuitive avenue of bypassing the hook completely. I am not 100% convinced that this is the better choice (but I am not convinced it is the worse one, either).
t/t4154-am-noverify.sh line 2
Quoted 8 lines
t/t4154-am-noverify.sh new file +2
-0@@ -0,0 +1,60 @@ +#!/bin/sh +
It is surprising, and I am not enthused to see, that this needs an entirely new script.
Don't we already have a script or two to test "am", among which the invocation of hooks is already tested?
Quoted 33 lines · Junio C Hamano
Quoted 13 lines · Thierry Reding
From: Thierry Reding <[email protected]>
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]>---
Changes in v2:
- add test to verify that the new option works+-n:: +--no-verify::Documentation/git-am.txt include::rerere-options.txt[] · line 145
Quoted 3 lines
Documentation/git-am.txt +3
-0+ By default, the pre-applypatch and applypatch-msg hooks are run. + When any of `--no-verify` or `-n` is given, these are bypassed. + See also linkgit:githooks[5].I think the goal of this topic is to allow bypassing the checks made by these two hooks (and possibly future ones that validate the input to "am"), and there are at least two possible implementations to achieve that goal. You can still run the hook and ignore its failure exit, or you can skip running the hook and pretend as if hook succeeded.
As it is documented that applypatch-msg is allowed to edit the message file to normalize the message, between the two, running the hook (to allow the hook to automatically edit the message) but ignoring its failure would be a more intuitive approach to "bypass" the check. If the option were called --no-hook or --bypass-hooks then it would be a different story, though.
Quoted 9 lines
builtin/am.c static void am_destroy(const struct am_state *state) · line 481
Quoted 5 lines
builtin/am.c +3
-1assert (state->msg); - ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL ); + +if (!state->no_verify) + ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL );And it seems that this took a less intuitive avenue of bypassing the hook completely. I am not 100% convinced that this is the better choice (but I am not convinced it is the worse one, either).
Thinking a bit more about this, if we let applypatch-msg run but ignore failures and continue on to commit the result, wouldn't that potentially allow committing garbage? I'm thinking about cases where applypatch-msg may attempt to normalize the message and fails badly, leaving a partial commit message or none at all.
The primary use-case where I'd like to use this new option for git am is when the pre-applypatch hook fails and that has less of the risks associated with applypatch-msg, so perhaps --no-verify should only apply to pre-applypatch?
Quoted 13 lines
t/t4154-am-noverify.sh line 2
Quoted 9 lines
t/t4154-am-noverify.sh new file +2
-0@@ -0,0 +1,60 @@ +#!/bin/sh +It is surprising, and I am not enthused to see, that this needs an entirely new script.
Quoted 2 lines
Don't we already have a script or two to test "am", among which the invocation of hooks is already tested?
I can move the tests to the corresponding sections in t/t4150-am.sh.
Thierry
Quoted 5 lines · Thierry Reding
Thinking a bit more about this, if we let applypatch-msg run but ignore failures and continue on to commit the result, wouldn't that potentially allow committing garbage? I'm thinking about cases where applypatch-msg may attempt to normalize the message and fails badly, leaving a partial commit message or none at all.
That is a very reasonable way to think about this. So I am sold on your approach of not running the hook at all.
Thanks.