Skip to content

Commit

Permalink
Merge branch 'jk/pretty-G-format-fixes' into maint
Browse files Browse the repository at this point in the history
"%G" (nothing after G) is an invalid pretty format specifier, but
the parser did not notice it as garbage.

* 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
  • Loading branch information
Junio C Hamano committed Jul 16, 2014
2 parents 5a3db94 + 958b2eb commit 588de86
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
if (c->signature_check.key)
strbuf_addstr(sb, c->signature_check.key);
break;
default:
return 0;
}
return 2;
}
Expand Down
6 changes: 6 additions & 0 deletions t/t6006-rev-list-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
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
71 changes: 62 additions & 9 deletions t/t7510-signed-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,44 @@ test_expect_success GPG 'create signed commits' '
test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
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' '
(
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
git show --pretty=short --show-signature $commit >actual &&
grep "Good signature from" actual || exit 1
! grep "BAD signature from" actual || exit 1
echo $commit OK
grep "Good signature from" actual &&
! grep "BAD signature from" actual &&
echo $commit OK || exit 1
done
) &&
(
for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
do
git show --pretty=short --show-signature $commit >actual &&
grep "Good signature from" actual && exit 1
! grep "BAD signature from" actual || exit 1
echo $commit OK
! grep "Good signature from" actual &&
! grep "BAD signature from" actual &&
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
)
'

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 &&
git hash-object -w -t commit forged1 >forged1.commit &&
Expand All @@ -77,7 +90,7 @@ test_expect_success GPG 'detect fudged signature' '
'

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 &&
echo Qwik | tr "Q" "\000" >>forged2 &&
git hash-object -w -t commit forged2 >forged2.commit &&
Expand All @@ -94,4 +107,44 @@ test_expect_success GPG 'amending already signed commit' '
! 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

0 comments on commit 588de86

Please sign in to comment.