git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: git@vger.kernel.org, Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH v4] am: Allow passing --no-verify flag
Date: Thu, 01 Dec 2022 09:51:46 +0900	[thread overview]
Message-ID: <xmqqr0xkt07x.fsf@gitster.g> (raw)
In-Reply-To: <20221130172833.2662751-1-thierry.reding@gmail.com> (Thierry Reding's message of "Wed, 30 Nov 2022 18:28:33 +0100")

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

> +		OPT_BOOL('n', "no-verify", &state.no_verify,
> +			N_("bypass pre-applypatch and applypatch-msg hooks")),

I think parse_options machinery is smart enough to do the right to
allow "git am --no-verify --verify" a way to express "last one wins,
turn the .no_verify bit off to countermand an earlier --no-verify",
so this looks good.

> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index cdad4b688078..d77c4dcefeb7 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -345,6 +345,22 @@ 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 &&
> +	echo hook-message >"$1"
> +	exit 1
> +	EOF
> +	git am --no-verify patch1 &&
> +	test_path_is_missing .git/rebase-apply &&
> +	git diff --exit-code second &&
> +	test_cmp_rev second HEAD &&

This somewhat raised my eyebrows, as the condition will not
generally hold.

I am guessing this was merely copied and pasted from the previous
test piece before this one, which uses "test_cmp_rev first HEAD" and
its use of test_cmp_rev is more sensible, as it is making sure that
"we started with 'first' commit at HEAD, 'am' should not have done
anything by failing, so expect HEAD is still at 'first'".

The reason to expect HEAD to be 'second' here is very different.  We
start from 'first', 'am' should have applied the patch as-is while
pretending that the wallclock is frozen (i.e. even the committer
timestamp should be the same as the original commit), so expect HEAD
is pointing at the exact same commit recreated by 'am'".  That is a
bit unrealistic expectation outside the context of the tests.

If we added test_commit or test_tick anywhere before this step in an
unrelated test, it likely will break this expectation; in other
words, I think the use of "test_cmp_rev second" here makes it
unnecessarily brittle.

> +	git log -1 --format=format:%B >actual &&
> +	test_cmp msg actual
> +'

Other than that, this test looks good.

> @@ -374,6 +390,22 @@ 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 &&
> +	touch empty-file &&
> +	test_hook pre-applypatch <<-\EOF &&
> +	rm empty-file
> +	exit 1
> +	EOF
> +	git am --no-verify patch1 &&
> +	test_path_is_missing .git/rebase-apply &&
> +	git diff --exit-code second &&
> +	test_cmp_rev second HEAD &&
> +	test_path_is_file empty-file
> +'

This "pre" stuff, unlike the other hook, does not affect the
resulting commit, so you invent an extra file "empty-file" as a
marker and remove it from the hook, so that the absense of the file
can be used as a signal that the hook did run.  We could do it the
other way around (i.e. make sure the marker file does not exist
before running "git am", arrange the marker to be created by running
the hook, and ensure that the marker does not exist after running
"git am"), and either way is fine.

The same comment as the previous one applies to "test_cmp_rev second"
check.  I think removing them would make the tests better.

Oh, also I keep forgetting but

> Subject: Re: [PATCH v4] am: Allow passing --no-verify flag

our convention is not capitalize "Allow" here.

Thanks.

  reply	other threads:[~2022-12-01  0:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 17:28 [PATCH v4] am: Allow passing --no-verify flag Thierry Reding
2022-12-01  0:51 ` Junio C Hamano [this message]
2022-12-01  0:55   ` Junio C Hamano
2022-12-21  9:20     ` Thierry Reding
2022-12-21  9:42       ` Junio C Hamano
2022-12-21 17:21         ` Thierry Reding
2022-12-25 11:26           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqr0xkt07x.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).