Skip to content

Commit 661a180

Browse files
Michael J Grubergitster
Michael J Gruber
authored andcommitted
gpg-interface: use more status letters
According to gpg2's doc/DETAILS: For each signature only one of the codes GOODSIG, BADSIG, EXPSIG, EXPKEYSIG, REVKEYSIG or ERRSIG will be emitted. gpg1 ("classic") behaves the same (although doc/DETAILS differs). Currently, we parse gpg's status output for GOODSIG, BADSIG and trust information and translate that into status codes G, B, U, N for the %G? format specifier. git-verify-* returns success in the GOODSIG case only. This is somewhat in disagreement with gpg, which considers the first 5 of the 6 above as VALIDSIG, but we err on the very safe side. Introduce additional status codes E, X, Y, R for ERRSIG, EXPSIG, EXPKEYSIG, and REVKEYSIG so that a user of %G? gets more information about the absence of a 'G' on first glance. Requested-by: Alex <[email protected]> Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21f862b commit 661a180

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Documentation/pretty-formats.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ ifndef::git-rev-list[]
143143
- '%N': commit notes
144144
endif::git-rev-list[]
145145
- '%GG': raw verification message from GPG for a signed commit
146-
- '%G?': show "G" for a good (valid) signature, "B" for a bad signature,
147-
"U" for a good signature with unknown validity and "N" for no signature
146+
- '%G?': show "G" for a good (valid) signature,
147+
"B" for a bad signature,
148+
"U" for a good signature with unknown validity,
149+
"X" for a good signature that has expired,
150+
"Y" for a good signature made by an expired key,
151+
"R" for a good signature made by a revoked key,
152+
"E" if the signature cannot be checked (e.g. missing key)
153+
and "N" for no signature
148154
- '%GS': show the name of the signer for a signed commit
149155
- '%GK': show the key used to sign a signed commit
150156
- '%gD': reflog selector, e.g., `refs/stash@{1}` or

gpg-interface.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ static struct {
3333
{ 'B', "\n[GNUPG:] BADSIG " },
3434
{ 'U', "\n[GNUPG:] TRUST_NEVER" },
3535
{ 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
36+
{ 'E', "\n[GNUPG:] ERRSIG "},
37+
{ 'X', "\n[GNUPG:] EXPSIG "},
38+
{ 'Y', "\n[GNUPG:] EXPKEYSIG "},
39+
{ 'R', "\n[GNUPG:] REVKEYSIG "},
3640
};
3741

3842
void parse_gpg_output(struct signature_check *sigc)
@@ -54,9 +58,12 @@ void parse_gpg_output(struct signature_check *sigc)
5458
/* The trust messages are not followed by key/signer information */
5559
if (sigc->result != 'U') {
5660
sigc->key = xmemdupz(found, 16);
57-
found += 17;
58-
next = strchrnul(found, '\n');
59-
sigc->signer = xmemdupz(found, next - found);
61+
/* The ERRSIG message is not followed by signer information */
62+
if (sigc-> result != 'E') {
63+
found += 17;
64+
next = strchrnul(found, '\n');
65+
sigc->signer = xmemdupz(found, next - found);
66+
}
6067
}
6168
}
6269
}

pretty.c

+4
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12321232
switch (c->signature_check.result) {
12331233
case 'G':
12341234
case 'B':
1235+
case 'E':
12351236
case 'U':
12361237
case 'N':
1238+
case 'X':
1239+
case 'Y':
1240+
case 'R':
12371241
strbuf_addch(sb, c->signature_check.result);
12381242
}
12391243
break;

t/t7510-signed-commit.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='signed commit tests'
44
. ./test-lib.sh
5+
GNUPGHOME_NOT_USED=$GNUPGHOME
56
. "$TEST_DIRECTORY/lib-gpg.sh"
67

78
test_expect_success GPG 'create signed commits' '
@@ -190,7 +191,7 @@ test_expect_success GPG 'show bad signature with custom format' '
190191
test_cmp expect actual
191192
'
192193

193-
test_expect_success GPG 'show unknown signature with custom format' '
194+
test_expect_success GPG 'show untrusted signature with custom format' '
194195
cat >expect <<-\EOF &&
195196
U
196197
61092E85B7227189
@@ -200,6 +201,16 @@ test_expect_success GPG 'show unknown signature with custom format' '
200201
test_cmp expect actual
201202
'
202203

204+
test_expect_success GPG 'show unknown signature with custom format' '
205+
cat >expect <<-\EOF &&
206+
E
207+
61092E85B7227189
208+
209+
EOF
210+
GNUPGHOME="$GNUPGHOME_NOT_USED" git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
211+
test_cmp expect actual
212+
'
213+
203214
test_expect_success GPG 'show lack of signature with custom format' '
204215
cat >expect <<-\EOF &&
205216
N

0 commit comments

Comments
 (0)