git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] am: add am.signoff add config variable

From
EHEduardo Habkost <ehabkost@redhat.com>
Date
Dec 28, 2016, 19:11 UTC
Message-ID
<20161228191142.GF3441@thinpad.lan.raisama.net>
In-Reply-To
<CAGZ79kaBpC5ym2N_fMZHDmL4gGpU8pFAsupCE4aTdENh+=z72g@mail.gmail.com>
On Wed, Dec 28, 2016 at 10:51:28AM -0800, Stefan Beller wrote:
Show 24 quoted lines
> 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
Previous: Stefan BellerNext: Eduardo Habkost
Message 3 of 9 in “am: add am.signoff add config variable”
  1. am: add am.signoff add config variableEduardo Habkost, Dec 28, 2016
  2. Stefan BellerDec 28, 2016
  3. Eduardo HabkostDec 28, 2016
  4. Eduardo HabkostDec 28, 2016
  5. Stefan BellerDec 28, 2016
  6. Pranit BauvaDec 29, 2016
  7. Eduardo HabkostDec 29, 2016
  8. Andreas SchwabDec 28, 2016
  9. Eduardo HabkostDec 28, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.