Skip to content

Commit 588de86

Browse files
committed
Merge branch 'jk/pretty-G-format-fixes' into maint
"%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
2 parents 5a3db94 + 958b2eb commit 588de86

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

pretty.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12491249
if (c->signature_check.key)
12501250
strbuf_addstr(sb, c->signature_check.key);
12511251
break;
1252+
default:
1253+
return 0;
12521254
}
12531255
return 2;
12541256
}

t/t6006-rev-list-format.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
468468
test_cmp expect actual
469469
'
470470

471+
test_expect_success 'unused %G placeholders are passed through' '
472+
echo "%GX %G" >expect &&
473+
git log -1 --format="%GX %G" >actual &&
474+
test_cmp expect actual
475+
'
476+
471477
test_done

t/t7510-signed-commit.sh

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,44 @@ test_expect_success GPG 'create signed commits' '
4343
4444
test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
4545
git tag seventh-signed
46+
47+
echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
48+
git tag eighth-signed-alt
4649
'
4750

4851
test_expect_success GPG 'show signatures' '
4952
(
50-
for commit in initial second merge fourth-signed fifth-signed sixth-signed master
53+
for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
5154
do
5255
git show --pretty=short --show-signature $commit >actual &&
53-
grep "Good signature from" actual || exit 1
54-
! grep "BAD signature from" actual || exit 1
55-
echo $commit OK
56+
grep "Good signature from" actual &&
57+
! grep "BAD signature from" actual &&
58+
echo $commit OK || exit 1
5659
done
5760
) &&
5861
(
5962
for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
6063
do
6164
git show --pretty=short --show-signature $commit >actual &&
62-
grep "Good signature from" actual && exit 1
63-
! grep "BAD signature from" actual || exit 1
64-
echo $commit OK
65+
! grep "Good signature from" actual &&
66+
! grep "BAD signature from" actual &&
67+
echo $commit OK || exit 1
68+
done
69+
) &&
70+
(
71+
for commit in eighth-signed-alt
72+
do
73+
git show --pretty=short --show-signature $commit >actual &&
74+
grep "Good signature from" actual &&
75+
! grep "BAD signature from" actual &&
76+
grep "not certified" actual &&
77+
echo $commit OK || exit 1
6578
done
6679
)
6780
'
6881

6982
test_expect_success GPG 'detect fudged signature' '
70-
git cat-file commit master >raw &&
83+
git cat-file commit seventh-signed >raw &&
7184
7285
sed -e "s/seventh/7th forged/" raw >forged1 &&
7386
git hash-object -w -t commit forged1 >forged1.commit &&
@@ -77,7 +90,7 @@ test_expect_success GPG 'detect fudged signature' '
7790
'
7891

7992
test_expect_success GPG 'detect fudged signature with NUL' '
80-
git cat-file commit master >raw &&
93+
git cat-file commit seventh-signed >raw &&
8194
cat raw >forged2 &&
8295
echo Qwik | tr "Q" "\000" >>forged2 &&
8396
git hash-object -w -t commit forged2 >forged2.commit &&
@@ -94,4 +107,44 @@ test_expect_success GPG 'amending already signed commit' '
94107
! grep "BAD signature from" actual
95108
'
96109

110+
test_expect_success GPG 'show good signature with custom format' '
111+
cat >expect <<-\EOF &&
112+
G
113+
13B6F51ECDDE430D
114+
C O Mitter <[email protected]>
115+
EOF
116+
git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
117+
test_cmp expect actual
118+
'
119+
120+
test_expect_success GPG 'show bad signature with custom format' '
121+
cat >expect <<-\EOF &&
122+
B
123+
13B6F51ECDDE430D
124+
C O Mitter <[email protected]>
125+
EOF
126+
git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
127+
test_cmp expect actual
128+
'
129+
130+
test_expect_success GPG 'show unknown signature with custom format' '
131+
cat >expect <<-\EOF &&
132+
U
133+
61092E85B7227189
134+
Eris Discordia <[email protected]>
135+
EOF
136+
git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
137+
test_cmp expect actual
138+
'
139+
140+
test_expect_success GPG 'show lack of signature with custom format' '
141+
cat >expect <<-\EOF &&
142+
N
143+
144+
145+
EOF
146+
git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
147+
test_cmp expect actual
148+
'
149+
97150
test_done

0 commit comments

Comments
 (0)