git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3] am: Allow passing --no-verify flag
@ 2022-11-28 17:48 Thierry Reding
  2022-11-28 23:07 ` Taylor Blau
  2022-11-29  1:20 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Thierry Reding @ 2022-11-28 17:48 UTC (permalink / raw)
  To: git; +Cc: Taylor Blau, Junio C Hamano

From: Thierry Reding <treding@nvidia.com>

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 <treding@nvidia.com>
---
Changes in v3:
- move tests to existing t/t4150-am

Changes in v2:
- add test to verify that the new option works

 Documentation/git-am.txt |  8 +++++++-
 builtin/am.c             | 11 ++++++++---
 t/t4150-am.sh            | 20 ++++++++++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 326276e51ce5..0c1dfb3c98b4 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -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
diff --git a/builtin/am.c b/builtin/am.c
index 30c9b3a9cd72..dfe8104f570d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -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))
@@ -2330,6 +2333,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,
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index cdad4b688078..84e6bebeca7a 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -345,6 +345,16 @@ test_expect_success 'am with failing applypatch-msg hook' '
 	test_cmp_rev first HEAD
 '
 
+test_expect_success 'am with failing applypatch-msg hook (no verify)' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	test_hook applypatch-msg <<-\EOF &&
+	exit 1
+	EOF
+	git am --no-verify patch1
+'
+
 test_expect_success 'am with pre-applypatch hook' '
 	rm -fr .git/rebase-apply &&
 	git reset --hard &&
@@ -374,6 +384,16 @@ test_expect_success 'am with failing pre-applypatch hook' '
 	test_cmp_rev first HEAD
 '
 
+test_expect_success 'am with failing pre-applypatch hook (no verify)' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	test_hook pre-applypatch <<-\EOF &&
+	exit 1
+	EOF
+	git am --no-verify patch1
+'
+
 test_expect_success 'am with post-applypatch hook' '
 	rm -fr .git/rebase-apply &&
 	git reset --hard &&
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] am: Allow passing --no-verify flag
  2022-11-28 17:48 [PATCH v3] am: Allow passing --no-verify flag Thierry Reding
@ 2022-11-28 23:07 ` Taylor Blau
  2022-11-29 10:02   ` Thierry Reding
  2022-11-29  1:20 ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Taylor Blau @ 2022-11-28 23:07 UTC (permalink / raw)
  To: Thierry Reding; +Cc: git, Junio C Hamano

Hi Thierry,

This is looking pretty good. Thanks for pushing out a couple of new
rounds. I took a look at the discussion and have some thoughts below,
but they are minor.

This will likely not be in the upcoming v2.39.0, since Junio has already
cut and pushed the first release candidate tag. But you should feel free
to keep working on it in the meantime and we can revisit it post-2.39.

On Mon, Nov 28, 2022 at 06:48:25PM +0100, Thierry Reding wrote:
> diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
> index 326276e51ce5..0c1dfb3c98b4 100644
> --- a/Documentation/git-am.txt
> +++ b/Documentation/git-am.txt
> @@ -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]

Spelling this as "[--no-verify]" and not "[--[no-]verify]" is right,
since the option itself is called "--no-verify" (and thus has the
OPT_NONEG flag bit set), and "--verify" does not exist. Good.

>  	 [--[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.

Should we be more explicit here, given the discussion in the earlier
rounds? IOW, instead of saying that they are "bypassed" (which might
lead the reader to believe that they are run and their output/exit code
ignored), should we say that they are "not run" and be clearer?

The (elided) implementation below looks good to me.

> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index cdad4b688078..84e6bebeca7a 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -345,6 +345,16 @@ test_expect_success 'am with failing applypatch-msg hook' '
>  	test_cmp_rev first HEAD
>  '
>
> +test_expect_success 'am with failing applypatch-msg hook (no verify)' '
> +	rm -fr .git/rebase-apply &&
> +	git reset --hard &&
> +	git checkout first &&
> +	test_hook applypatch-msg <<-\EOF &&
> +	exit 1
> +	EOF
> +	git am --no-verify patch1

Should we verify that the patch was applied with the expected message?

> +'
> +
>  test_expect_success 'am with pre-applypatch hook' '
>  	rm -fr .git/rebase-apply &&
>  	git reset --hard &&
> @@ -374,6 +384,16 @@ test_expect_success 'am with failing pre-applypatch hook' '
>  	test_cmp_rev first HEAD
>  '
>
> +test_expect_success 'am with failing pre-applypatch hook (no verify)' '
> +	rm -fr .git/rebase-apply &&
> +	git reset --hard &&
> +	git checkout first &&
> +	test_hook pre-applypatch <<-\EOF &&
> +	exit 1
> +	EOF
> +	git am --no-verify patch1

Ditto here.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] am: Allow passing --no-verify flag
  2022-11-28 17:48 [PATCH v3] am: Allow passing --no-verify flag Thierry Reding
  2022-11-28 23:07 ` Taylor Blau
@ 2022-11-29  1:20 ` Junio C Hamano
  2022-11-29 10:03   ` Thierry Reding
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2022-11-29  1:20 UTC (permalink / raw)
  To: Thierry Reding; +Cc: git, Taylor Blau

Thierry Reding <thierry.reding@gmail.com> writes:

> +test_expect_success 'am with failing applypatch-msg hook (no verify)' '
> +	rm -fr .git/rebase-apply &&
> +	git reset --hard &&
> +	git checkout first &&
> +	test_hook applypatch-msg <<-\EOF &&
> +	exit 1
> +	EOF
> +	git am --no-verify patch1
> +'
> +
>  test_expect_success 'am with pre-applypatch hook' '
>  	rm -fr .git/rebase-apply &&
>  	git reset --hard &&
> @@ -374,6 +384,16 @@ test_expect_success 'am with failing pre-applypatch hook' '
>  	test_cmp_rev first HEAD
>  '
>  
> +test_expect_success 'am with failing pre-applypatch hook (no verify)' '
> +	rm -fr .git/rebase-apply &&
> +	git reset --hard &&
> +	git checkout first &&
> +	test_hook pre-applypatch <<-\EOF &&
> +	exit 1
> +	EOF
> +	git am --no-verify patch1
> +'
> +
>  test_expect_success 'am with post-applypatch hook' '
>  	rm -fr .git/rebase-apply &&
>  	git reset --hard &&

These two tests will still pass if you change the implementation to
run the hook and simply ignore its exit status, but I recall you
making a good argument against that alternative implementation ,in
comparison to "not running the hook at all".

I think these tests should make sure that the hooks did not even
run.  Perhaps by creating a marker file before running "git am",
adding a "rm" that marker file in the hook, and making sure that
the marker file still exists after "git am" returns, or something
like that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] am: Allow passing --no-verify flag
  2022-11-28 23:07 ` Taylor Blau
@ 2022-11-29 10:02   ` Thierry Reding
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2022-11-29 10:02 UTC (permalink / raw)
  To: Taylor Blau; +Cc: git, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 3435 bytes --]

On Mon, Nov 28, 2022 at 06:07:38PM -0500, Taylor Blau wrote:
> Hi Thierry,
> 
> This is looking pretty good. Thanks for pushing out a couple of new
> rounds. I took a look at the discussion and have some thoughts below,
> but they are minor.
> 
> This will likely not be in the upcoming v2.39.0, since Junio has already
> cut and pushed the first release candidate tag. But you should feel free
> to keep working on it in the meantime and we can revisit it post-2.39.

That's fine. No rush. I've had local workarounds for this for a very
long time, so I can be patient for a little longer. =)

> On Mon, Nov 28, 2022 at 06:48:25PM +0100, Thierry Reding wrote:
> > diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
> > index 326276e51ce5..0c1dfb3c98b4 100644
> > --- a/Documentation/git-am.txt
> > +++ b/Documentation/git-am.txt
> > @@ -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]
> 
> Spelling this as "[--no-verify]" and not "[--[no-]verify]" is right,
> since the option itself is called "--no-verify" (and thus has the
> OPT_NONEG flag bit set), and "--verify" does not exist. Good.
> 
> >  	 [--[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.
> 
> Should we be more explicit here, given the discussion in the earlier
> rounds? IOW, instead of saying that they are "bypassed" (which might
> lead the reader to believe that they are run and their output/exit code
> ignored), should we say that they are "not run" and be clearer?

I adopted the wording as for git commit and since the behavior is
exactly the same, it seemed best to stay consistent with that. My
interpretation of "bypassed" is equivalent to "unused" or "ignored",
though "ignored" in this case relating to their existence rather than
return value.

Either wording is fine with me, so if you feel strongly I can reword
this. In that case it might be worth updating the git commit
documentation as well to avoid the same ambiguity.

> 
> The (elided) implementation below looks good to me.
> 
> > diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> > index cdad4b688078..84e6bebeca7a 100755
> > --- a/t/t4150-am.sh
> > +++ b/t/t4150-am.sh
> > @@ -345,6 +345,16 @@ test_expect_success 'am with failing applypatch-msg hook' '
> >  	test_cmp_rev first HEAD
> >  '
> >
> > +test_expect_success 'am with failing applypatch-msg hook (no verify)' '
> > +	rm -fr .git/rebase-apply &&
> > +	git reset --hard &&
> > +	git checkout first &&
> > +	test_hook applypatch-msg <<-\EOF &&
> > +	exit 1
> > +	EOF
> > +	git am --no-verify patch1
> 
> Should we verify that the patch was applied with the expected message?

Yes, that's a good point. I've updated both tests to check that the
patch has been applied and the scripts haven't been run.

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] am: Allow passing --no-verify flag
  2022-11-29  1:20 ` Junio C Hamano
@ 2022-11-29 10:03   ` Thierry Reding
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2022-11-29 10:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Taylor Blau

[-- Attachment #1: Type: text/plain, Size: 1762 bytes --]

On Tue, Nov 29, 2022 at 10:20:05AM +0900, Junio C Hamano wrote:
> Thierry Reding <thierry.reding@gmail.com> writes:
> 
> > +test_expect_success 'am with failing applypatch-msg hook (no verify)' '
> > +	rm -fr .git/rebase-apply &&
> > +	git reset --hard &&
> > +	git checkout first &&
> > +	test_hook applypatch-msg <<-\EOF &&
> > +	exit 1
> > +	EOF
> > +	git am --no-verify patch1
> > +'
> > +
> >  test_expect_success 'am with pre-applypatch hook' '
> >  	rm -fr .git/rebase-apply &&
> >  	git reset --hard &&
> > @@ -374,6 +384,16 @@ test_expect_success 'am with failing pre-applypatch hook' '
> >  	test_cmp_rev first HEAD
> >  '
> >  
> > +test_expect_success 'am with failing pre-applypatch hook (no verify)' '
> > +	rm -fr .git/rebase-apply &&
> > +	git reset --hard &&
> > +	git checkout first &&
> > +	test_hook pre-applypatch <<-\EOF &&
> > +	exit 1
> > +	EOF
> > +	git am --no-verify patch1
> > +'
> > +
> >  test_expect_success 'am with post-applypatch hook' '
> >  	rm -fr .git/rebase-apply &&
> >  	git reset --hard &&
> 
> These two tests will still pass if you change the implementation to
> run the hook and simply ignore its exit status, but I recall you
> making a good argument against that alternative implementation ,in
> comparison to "not running the hook at all".
> 
> I think these tests should make sure that the hooks did not even
> run.  Perhaps by creating a marker file before running "git am",
> adding a "rm" that marker file in the hook, and making sure that
> the marker file still exists after "git am" returns, or something
> like that.

All good points. I've updated both tests to check that patches have been
applied correctly and that the scripts haven't been run.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-29 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 17:48 [PATCH v3] am: Allow passing --no-verify flag Thierry Reding
2022-11-28 23:07 ` Taylor Blau
2022-11-29 10:02   ` Thierry Reding
2022-11-29  1:20 ` Junio C Hamano
2022-11-29 10:03   ` Thierry Reding

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).