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 <[email protected]>
> > 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