git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2] am: add am.signoff add config variable
@ 2016-12-28 18:35 Eduardo Habkost
  2016-12-28 18:51 ` Stefan Beller
  2016-12-28 19:07 ` Andreas Schwab
  0 siblings, 2 replies; 9+ messages in thread
From: Eduardo Habkost @ 2016-12-28 18:35 UTC (permalink / raw)
  To: git; +Cc: Paul Tan, Stefan Beller

git-am has options to enable --message-id and --3way by default,
but no option to enable --signoff by default. Add a "am.signoff"
config option.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Added documentation to Documentation/git-am.txt and
  Documentation/config.txt
* Added test cases to t4150-am.sh
---
 Documentation/config.txt |  5 +++++
 Documentation/git-am.txt |  6 ++++--
 builtin/am.c             |  2 ++
 t/t4150-am.sh            | 24 ++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 30cb94610..6b2990203 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -822,6 +822,11 @@ am.keepcr::
 	by giving `--no-keep-cr` from the command line.
 	See linkgit:git-am[1], linkgit:git-mailsplit[1].
 
+am.signoff::
+	If true, git-am will add a `Signed-off-by:` line to the commit
+	message. See the signoff option in linkgit:git-commit[1] for
+	more information.
+
 am.threeWay::
 	By default, `git am` will fail if the patch does not apply cleanly. When
 	set to true, this setting tells `git am` to fall back on 3-way merge if
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 12879e402..f22f10d40 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' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
 	 [--[no-]3way] [--interactive] [--committer-date-is-author-date]
 	 [--ignore-date] [--ignore-space-change | --ignore-whitespace]
 	 [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -32,10 +32,12 @@ OPTIONS
 	If you supply directories, they will be treated as Maildirs.
 
 -s::
---signoff::
+--[no]-signoff::
 	Add a `Signed-off-by:` line to the commit message, using
 	the committer identity of yourself.
 	See the signoff option in linkgit:git-commit[1] for more information.
+	The `am.signoff` configuration variable can be used to specify the
+	default behaviour.  `--no-signoff` is useful to override `am.signoff`.
 
 -k::
 --keep::
diff --git a/builtin/am.c b/builtin/am.c
index 31fb60578..d2e02334f 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -154,6 +154,8 @@ static void am_state_init(struct am_state *state, const char *dir)
 
 	git_config_get_bool("am.messageid", &state->message_id);
 
+	git_config_get_bool("am.signoff", &state->signoff);
+
 	state->scissors = SCISSORS_UNSET;
 
 	argv_array_init(&state->git_apply_opts);
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 89a5bacac..41b5481c9 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -479,6 +479,30 @@ test_expect_success 'am --signoff adds Signed-off-by: line' '
 	test_cmp expected actual
 '
 
+test_expect_success '--no-signoff overrides am.signoff' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard first &&
+	test_config am.signoff true &&
+	git am --no-signoff <patch2 &&
+	printf "%s\n" "$signoff" >expected &&
+	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
+	test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
+'
+
+test_expect_success 'am.signoff adds Signed-off-by: line' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard first &&
+	test_config am.signoff true &&
+	git am <patch2 &&
+	printf "%s\n" "$signoff" >expected &&
+	echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
+	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
+	test_cmp expected actual &&
+	echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
+	git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'am stays in branch' '
 	echo refs/heads/master2 >expected &&
 	git symbolic-ref HEAD >actual &&
-- 
2.11.0.259.g40922b1


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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 18:35 [PATCH v2] am: add am.signoff add config variable Eduardo Habkost
@ 2016-12-28 18:51 ` Stefan Beller
  2016-12-28 19:11   ` Eduardo Habkost
  2016-12-28 19:07 ` Andreas Schwab
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Beller @ 2016-12-28 18:51 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: git@vger.kernel.org, Paul Tan

On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> git-am has options to enable --message-id and --3way by default,
> but no option to enable --signoff by default. Add a "am.signoff"
> config option.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * Added documentation to Documentation/git-am.txt and
>   Documentation/config.txt
> * Added test cases to t4150-am.sh

Thanks!
Documentation and code looks good to me, for the test a small nit below.

> +test_expect_success '--no-signoff overrides am.signoff' '
> +       rm -fr .git/rebase-apply &&
> +       git reset --hard first &&
> +       test_config am.signoff true &&
> +       git am --no-signoff <patch2 &&
> +       printf "%s\n" "$signoff" >expected &&

"expected" is never read in this test, so we can omit this line?

> +       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&

So we check if the previous commit is not tampered with,

> +       test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0

and then we check if the top most commit has zero occurrences
for lines grepped for sign off. That certainly works, but took me a
while to understand (TIL about -c in grep :).

Another way that to write this check, that Git regulars may be more used to is:

    git cat-file commit HEAD | grep "Signed-off-by:" >actual
    test_must_be_empty actual

I would have suggested to grep for $signoff instead of "Signed-off-by:",
but it turns out being fuzzy here is better and would also catch e.g.
a broken sign off.

> +test_expect_success 'am.signoff adds Signed-off-by: line' '
> +       rm -fr .git/rebase-apply &&
> +       git reset --hard first &&
> +       test_config am.signoff true &&
> +       git am <patch2 &&
> +       printf "%s\n" "$signoff" >expected &&
> +       echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
> +       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
> +       test_cmp expected actual &&
> +       echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
> +       git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
> +       test_cmp expected actual
> +'

This test looks good to me,

Thanks,
Stefan

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 18:35 [PATCH v2] am: add am.signoff add config variable Eduardo Habkost
  2016-12-28 18:51 ` Stefan Beller
@ 2016-12-28 19:07 ` Andreas Schwab
  2016-12-28 19:12   ` Eduardo Habkost
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2016-12-28 19:07 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: git, Paul Tan, Stefan Beller

On Dez 28 2016, Eduardo Habkost <ehabkost@redhat.com> wrote:

> diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
> index 12879e402..f22f10d40 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' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
>  	 [--[no-]3way] [--interactive] [--committer-date-is-author-date]
>  	 [--ignore-date] [--ignore-space-change | --ignore-whitespace]
>  	 [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
> @@ -32,10 +32,12 @@ OPTIONS
>  	If you supply directories, they will be treated as Maildirs.
>  
>  -s::
> ---signoff::
> +--[no]-signoff::

That should be --[no-]signoff, as in the synopsis.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 18:51 ` Stefan Beller
@ 2016-12-28 19:11   ` Eduardo Habkost
  2016-12-28 19:19     ` Eduardo Habkost
  0 siblings, 1 reply; 9+ messages in thread
From: Eduardo Habkost @ 2016-12-28 19:11 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, Paul Tan

On Wed, Dec 28, 2016 at 10:51:28AM -0800, Stefan Beller wrote:
> On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > git-am has options to enable --message-id and --3way by default,
> > but no option to enable --signoff by default. Add a "am.signoff"
> > config option.
> >
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > Changes v1 -> v2:
> > * Added documentation to Documentation/git-am.txt and
> >   Documentation/config.txt
> > * Added test cases to t4150-am.sh
> 
> Thanks!
> Documentation and code looks good to me, for the test a small nit below.
> 
> > +test_expect_success '--no-signoff overrides am.signoff' '
> > +       rm -fr .git/rebase-apply &&
> > +       git reset --hard first &&
> > +       test_config am.signoff true &&
> > +       git am --no-signoff <patch2 &&
> > +       printf "%s\n" "$signoff" >expected &&
> 
> "expected" is never read in this test, so we can omit this line?
> 

Oops, I have deleted a "test_cmp expected actual" line by mistake.

> > +       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
> 
> So we check if the previous commit is not tampered with,

We do, but only if we have a "test_cmp expected actual" line
here.

Fixed by:

diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 41b5481c9..d4b6a832f 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -486,6 +486,7 @@ test_expect_success '--no-signoff overrides am.signoff' '
 	git am --no-signoff <patch2 &&
 	printf "%s\n" "$signoff" >expected &&
 	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
+	test_cmp expected actual &&
 	test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
 '
 
> 
> > +       test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
> 
> and then we check if the top most commit has zero occurrences
> for lines grepped for sign off. That certainly works, but took me a
> while to understand (TIL about -c in grep :).
> 
> Another way that to write this check, that Git regulars may be more used to is:
> 
>     git cat-file commit HEAD | grep "Signed-off-by:" >actual
>     test_must_be_empty actual

test_must_be_empty is what I was looking for. But if I do this:

test_expect_success '--no-signoff overrides am.signoff' '
	rm -fr .git/rebase-apply &&
	git reset --hard first &&
	test_config am.signoff true &&
	git am --no-signoff <patch2 &&
	printf "%s\n" "$signoff" >expected &&
	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
	test_cmp expected actual &&
	git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
	test_must_be_empty actual
'

The test fails because the second "grep" command returns a
non-zero exit code. Any suggestions to avoid that problem in a
more idiomatic way?

> 
> I would have suggested to grep for $signoff instead of "Signed-off-by:",
> but it turns out being fuzzy here is better and would also catch e.g.
> a broken sign off.

Yes, I want to ensure no extra Signed-off-by line is present
except for $signof (that is already present in the original
e-mail).

> 
> > +test_expect_success 'am.signoff adds Signed-off-by: line' '
> > +       rm -fr .git/rebase-apply &&
> > +       git reset --hard first &&
> > +       test_config am.signoff true &&
> > +       git am <patch2 &&
> > +       printf "%s\n" "$signoff" >expected &&
> > +       echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
> > +       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
> > +       test_cmp expected actual &&
> > +       echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
> > +       git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
> > +       test_cmp expected actual
> > +'
> 
> This test looks good to me,
> 
> Thanks,
> Stefan

-- 
Eduardo

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 19:07 ` Andreas Schwab
@ 2016-12-28 19:12   ` Eduardo Habkost
  0 siblings, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2016-12-28 19:12 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: git, Paul Tan, Stefan Beller

On Wed, Dec 28, 2016 at 08:07:54PM +0100, Andreas Schwab wrote:
> On Dez 28 2016, Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
> > index 12879e402..f22f10d40 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' [--[no-]signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
> >  	 [--[no-]3way] [--interactive] [--committer-date-is-author-date]
> >  	 [--ignore-date] [--ignore-space-change | --ignore-whitespace]
> >  	 [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
> > @@ -32,10 +32,12 @@ OPTIONS
> >  	If you supply directories, they will be treated as Maildirs.
> >  
> >  -s::
> > ---signoff::
> > +--[no]-signoff::
> 
> That should be --[no-]signoff, as in the synopsis.

Thanks for catching it. I will fix it in v3.

-- 
Eduardo

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 19:11   ` Eduardo Habkost
@ 2016-12-28 19:19     ` Eduardo Habkost
  2016-12-28 19:24       ` Stefan Beller
  2016-12-29  7:59       ` Pranit Bauva
  0 siblings, 2 replies; 9+ messages in thread
From: Eduardo Habkost @ 2016-12-28 19:19 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org, Paul Tan

On Wed, Dec 28, 2016 at 05:11:42PM -0200, Eduardo Habkost wrote:
> On Wed, Dec 28, 2016 at 10:51:28AM -0800, Stefan Beller wrote:
> > On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
[...]
> > > +       test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
> > 
> > and then we check if the top most commit has zero occurrences
> > for lines grepped for sign off. That certainly works, but took me a
> > while to understand (TIL about -c in grep :).
> > 
> > Another way that to write this check, that Git regulars may be more used to is:
> > 
> >     git cat-file commit HEAD | grep "Signed-off-by:" >actual
> >     test_must_be_empty actual
> 
> test_must_be_empty is what I was looking for. But if I do this:
> 
> test_expect_success '--no-signoff overrides am.signoff' '
> 	rm -fr .git/rebase-apply &&
> 	git reset --hard first &&
> 	test_config am.signoff true &&
> 	git am --no-signoff <patch2 &&
> 	printf "%s\n" "$signoff" >expected &&
> 	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
> 	test_cmp expected actual &&
> 	git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
> 	test_must_be_empty actual
> '
> 
> The test fails because the second "grep" command returns a
> non-zero exit code. Any suggestions to avoid that problem in a
> more idiomatic way?

I just found out that "test_must_fail grep ..." is a common
idiom, so what about:

test_expect_success '--no-signoff overrides am.signoff' '
	rm -fr .git/rebase-apply &&
	git reset --hard first &&
	test_config am.signoff true &&
	git am --no-signoff <patch2 &&
	printf "%s\n" "$signoff" >expected &&
	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
	test_cmp expected actual &&
	git cat-file commit HEAD | test_must_fail grep -q "Signed-off-by:"
'

-- 
Eduardo

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 19:19     ` Eduardo Habkost
@ 2016-12-28 19:24       ` Stefan Beller
  2016-12-29  7:59       ` Pranit Bauva
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Beller @ 2016-12-28 19:24 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: git@vger.kernel.org, Paul Tan

On Wed, Dec 28, 2016 at 11:19 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Wed, Dec 28, 2016 at 05:11:42PM -0200, Eduardo Habkost wrote:
>> On Wed, Dec 28, 2016 at 10:51:28AM -0800, Stefan Beller wrote:
>> > On Wed, Dec 28, 2016 at 10:35 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> [...]
>> > > +       test $(git cat-file commit HEAD | grep -c "Signed-off-by:") -eq 0
>> >
>> > and then we check if the top most commit has zero occurrences
>> > for lines grepped for sign off. That certainly works, but took me a
>> > while to understand (TIL about -c in grep :).
>> >
>> > Another way that to write this check, that Git regulars may be more used to is:
>> >
>> >     git cat-file commit HEAD | grep "Signed-off-by:" >actual
>> >     test_must_be_empty actual
>>
>> test_must_be_empty is what I was looking for. But if I do this:
>>
>> test_expect_success '--no-signoff overrides am.signoff' '
>>       rm -fr .git/rebase-apply &&
>>       git reset --hard first &&
>>       test_config am.signoff true &&
>>       git am --no-signoff <patch2 &&
>>       printf "%s\n" "$signoff" >expected &&
>>       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
>>       test_cmp expected actual &&
>>       git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
>>       test_must_be_empty actual
>> '
>>
>> The test fails because the second "grep" command returns a
>> non-zero exit code. Any suggestions to avoid that problem in a
>> more idiomatic way?
>
> I just found out that "test_must_fail grep ..." is a common
> idiom, so what about:

Uh, no please.

test_must_fail is supposed to be used for commands to be tested, i.e.
git commands as this is the git test suite. :)
test_must_fail checks, e.g. that the failing command "properly" fails
instead of bye-bye-segfault. And grep would never do this. (In this
world we assume everything to be perfect except git itself)

For grep just use !

    git cat-file commit HEAD >actual &&
    ! grep "Signed-off-by:" actual

$ git grep "test_must_fail grep" returns 20 occurrences, so in case you're
that would be a good cleanup patch (if you're interested in such things).

Thanks,
Stefan

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-28 19:19     ` Eduardo Habkost
  2016-12-28 19:24       ` Stefan Beller
@ 2016-12-29  7:59       ` Pranit Bauva
  2016-12-29 15:37         ` Eduardo Habkost
  1 sibling, 1 reply; 9+ messages in thread
From: Pranit Bauva @ 2016-12-29  7:59 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Stefan Beller, git@vger.kernel.org, Paul Tan

Hey Eduardo,

On Thu, Dec 29, 2016 at 12:49 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
>> test_expect_success '--no-signoff overrides am.signoff' '
>>       rm -fr .git/rebase-apply &&
>>       git reset --hard first &&
>>       test_config am.signoff true &&
>>       git am --no-signoff <patch2 &&
>>       printf "%s\n" "$signoff" >expected &&
>>       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
>>       test_cmp expected actual &&
>>       git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
>>       test_must_be_empty actual
>> '
>>
>> The test fails because the second "grep" command returns a
>> non-zero exit code. Any suggestions to avoid that problem in a
>> more idiomatic way?
>
> I just found out that "test_must_fail grep ..." is a common
> idiom, so what about:

Is there any particular reason to use "grep" instead of "test_cmp"? To
check for non-zero error code, you can always use "! test_cmp".

Regards,
Pranit Bauva

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

* Re: [PATCH v2] am: add am.signoff add config variable
  2016-12-29  7:59       ` Pranit Bauva
@ 2016-12-29 15:37         ` Eduardo Habkost
  0 siblings, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2016-12-29 15:37 UTC (permalink / raw)
  To: Pranit Bauva; +Cc: Stefan Beller, git@vger.kernel.org, Paul Tan

On Thu, Dec 29, 2016 at 01:29:33PM +0530, Pranit Bauva wrote:
> Hey Eduardo,
> 
> On Thu, Dec 29, 2016 at 12:49 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> >> test_expect_success '--no-signoff overrides am.signoff' '
> >>       rm -fr .git/rebase-apply &&
> >>       git reset --hard first &&
> >>       test_config am.signoff true &&
> >>       git am --no-signoff <patch2 &&
> >>       printf "%s\n" "$signoff" >expected &&
> >>       git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
> >>       test_cmp expected actual &&
> >>       git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
> >>       test_must_be_empty actual
> >> '
> >>
> >> The test fails because the second "grep" command returns a
> >> non-zero exit code. Any suggestions to avoid that problem in a
> >> more idiomatic way?
> >
> > I just found out that "test_must_fail grep ..." is a common
> > idiom, so what about:
> 
> Is there any particular reason to use "grep" instead of "test_cmp"? To
> check for non-zero error code, you can always use "! test_cmp".

The test code is checking only the "Signed-off-by" lines, not the
whole commit message. "test_cmp" would require recovering the
entire contents of the original commit message, which would add
complexity to the test code.

-- 
Eduardo

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

end of thread, other threads:[~2016-12-29 15:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28 18:35 [PATCH v2] am: add am.signoff add config variable Eduardo Habkost
2016-12-28 18:51 ` Stefan Beller
2016-12-28 19:11   ` Eduardo Habkost
2016-12-28 19:19     ` Eduardo Habkost
2016-12-28 19:24       ` Stefan Beller
2016-12-29  7:59       ` Pranit Bauva
2016-12-29 15:37         ` Eduardo Habkost
2016-12-28 19:07 ` Andreas Schwab
2016-12-28 19:12   ` Eduardo Habkost

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