Merge branch 'jk/pretty-G-format-fixes'

* jk/pretty-G-format-fixes:
  move "%G" format test from t7510 to t6006
  pretty: avoid reading past end-of-string with "%G"
  t7510: check %G* pretty-format output
  t7510: test a commit signed by an unknown key
  t7510: use consistent &&-chains in loop
  t7510: stop referring to master in later tests
This commit is contained in:
Junio C Hamano 2014-07-09 11:34:13 -07:00
commit ce8350f8ea
3 changed files with 70 additions and 9 deletions

View File

@ -1248,6 +1248,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
if (c->signature_check.key) if (c->signature_check.key)
strbuf_addstr(sb, c->signature_check.key); strbuf_addstr(sb, c->signature_check.key);
break; break;
default:
return 0;
} }
return 2; return 2;
} }

View File

@ -468,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'unused %G placeholders are passed through' '
echo "%GX %G" >expect &&
git log -1 --format="%GX %G" >actual &&
test_cmp expect actual
'
test_done test_done

View File

@ -43,31 +43,44 @@ test_expect_success GPG 'create signed commits' '
test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ && test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
git tag seventh-signed git tag seventh-signed
echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
git tag eighth-signed-alt
' '
test_expect_success GPG 'show signatures' ' test_expect_success GPG 'show signatures' '
( (
for commit in initial second merge fourth-signed fifth-signed sixth-signed master for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
do do
git show --pretty=short --show-signature $commit >actual && git show --pretty=short --show-signature $commit >actual &&
grep "Good signature from" actual || exit 1 grep "Good signature from" actual &&
! grep "BAD signature from" actual || exit 1 ! grep "BAD signature from" actual &&
echo $commit OK echo $commit OK || exit 1
done done
) && ) &&
( (
for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
do do
git show --pretty=short --show-signature $commit >actual && git show --pretty=short --show-signature $commit >actual &&
grep "Good signature from" actual && exit 1 ! grep "Good signature from" actual &&
! grep "BAD signature from" actual || exit 1 ! grep "BAD signature from" actual &&
echo $commit OK echo $commit OK || exit 1
done
) &&
(
for commit in eighth-signed-alt
do
git show --pretty=short --show-signature $commit >actual &&
grep "Good signature from" actual &&
! grep "BAD signature from" actual &&
grep "not certified" actual &&
echo $commit OK || exit 1
done done
) )
' '
test_expect_success GPG 'detect fudged signature' ' test_expect_success GPG 'detect fudged signature' '
git cat-file commit master >raw && git cat-file commit seventh-signed >raw &&
sed -e "s/seventh/7th forged/" raw >forged1 && sed -e "s/seventh/7th forged/" raw >forged1 &&
git hash-object -w -t commit forged1 >forged1.commit && git hash-object -w -t commit forged1 >forged1.commit &&
@ -77,7 +90,7 @@ test_expect_success GPG 'detect fudged signature' '
' '
test_expect_success GPG 'detect fudged signature with NUL' ' test_expect_success GPG 'detect fudged signature with NUL' '
git cat-file commit master >raw && git cat-file commit seventh-signed >raw &&
cat raw >forged2 && cat raw >forged2 &&
echo Qwik | tr "Q" "\000" >>forged2 && echo Qwik | tr "Q" "\000" >>forged2 &&
git hash-object -w -t commit forged2 >forged2.commit && git hash-object -w -t commit forged2 >forged2.commit &&
@ -94,4 +107,44 @@ test_expect_success GPG 'amending already signed commit' '
! grep "BAD signature from" actual ! grep "BAD signature from" actual
' '
test_expect_success GPG 'show good signature with custom format' '
cat >expect <<-\EOF &&
G
13B6F51ECDDE430D
C O Mitter <committer@example.com>
EOF
git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
test_cmp expect actual
'
test_expect_success GPG 'show bad signature with custom format' '
cat >expect <<-\EOF &&
B
13B6F51ECDDE430D
C O Mitter <committer@example.com>
EOF
git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
test_cmp expect actual
'
test_expect_success GPG 'show unknown signature with custom format' '
cat >expect <<-\EOF &&
U
61092E85B7227189
Eris Discordia <discord@example.net>
EOF
git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
test_cmp expect actual
'
test_expect_success GPG 'show lack of signature with custom format' '
cat >expect <<-\EOF &&
N
EOF
git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
test_cmp expect actual
'
test_done test_done