Skip to content

Commit 56d268b

Browse files
committed
Merge branch 'mg/gpg-richer-status'
The GPG verification status shown in "%G?" pretty format specifier was not rich enough to differentiate a signature made by an expired key, a signature made by a revoked key, etc. New output letters have been assigned to express them. * mg/gpg-richer-status: gpg-interface: use more status letters
2 parents a039738 + 661a180 commit 56d268b

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
@@ -1230,8 +1230,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12301230
switch (c->signature_check.result) {
12311231
case 'G':
12321232
case 'B':
1233+
case 'E':
12331234
case 'U':
12341235
case 'N':
1236+
case 'X':
1237+
case 'Y':
1238+
case 'R':
12351239
strbuf_addch(sb, c->signature_check.result);
12361240
}
12371241
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)