Skip to content

Commit 4e87b25

Browse files
authored
enhance: show commit signer (#626)
Signed-off-by: Gadfly <[email protected]>
1 parent e680f84 commit 4e87b25

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/Commands/QueryCommitSignInfo.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ public QueryCommitSignInfo(string repo, string sha, bool useFakeSignersFile)
77
WorkingDirectory = repo;
88
Context = repo;
99

10-
if (useFakeSignersFile)
11-
Args = $"-c gpg.ssh.allowedSignersFile=/dev/null show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}";
12-
else
13-
Args = $"show --no-show-signature --pretty=format:\"%G? %GK\" -s {sha}";
10+
const string baseArgs = "show --no-show-signature --pretty=format:\"%G?%n%GS%n%GK\" -s";
11+
const string fakeSignersFileArg = "-c gpg.ssh.allowedSignersFile=/dev/null";
12+
Args = $"{(useFakeSignersFile ? fakeSignersFileArg : string.Empty)} {baseArgs} {sha}";
1413
}
1514

1615
public Models.CommitSignInfo Result()
@@ -20,10 +19,17 @@ public Models.CommitSignInfo Result()
2019
return null;
2120

2221
var raw = rs.StdOut.Trim();
23-
if (raw.Length > 1)
24-
return new Models.CommitSignInfo() { VerifyResult = raw[0], Key = raw.Substring(2) };
22+
if (raw.Length <= 1)
23+
return null;
24+
25+
var lines = raw.Split('\n');
26+
return new Models.CommitSignInfo()
27+
{
28+
VerifyResult = lines[0][0],
29+
Signer = string.IsNullOrEmpty(lines[1]) ? "<UnKnown>" : lines[1],
30+
Key = lines[2]
31+
};
2532

26-
return null;
2733
}
2834
}
2935
}

src/Models/CommitSignInfo.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ namespace SourceGit.Models
44
{
55
public class CommitSignInfo
66
{
7-
public string Key { get; set; } = string.Empty;
8-
public char VerifyResult { get; set; } = 'N';
7+
public char VerifyResult { get; init; } = 'N';
8+
public string Signer { get; init; } = string.Empty;
9+
public string Key { get; init; } = string.Empty;
910

1011
public IBrush Brush
1112
{
@@ -36,19 +37,19 @@ public string ToolTip
3637
switch (VerifyResult)
3738
{
3839
case 'G':
39-
return $"Good signature.\n\nKey: {Key}";
40+
return $"Good signature.\n\nSigner: {Signer}\n\nKey: {Key}";
4041
case 'B':
41-
return $"Bad signature.\n\nKey: {Key}";
42+
return $"Bad signature.\n\nSigner: {Signer}\n\nKey: {Key}";
4243
case 'U':
43-
return $"Good signature with unknown validity.\n\nKey: {Key}";
44+
return $"Good signature with unknown validity.\n\nSigner: {Signer}\n\nKey: {Key}";
4445
case 'X':
45-
return $"Good signature but has expired.\n\nKey: {Key}";
46+
return $"Good signature but has expired.\n\nSigner: {Signer}\n\nKey: {Key}";
4647
case 'Y':
47-
return $"Good signature made by expired key.\n\nKey: {Key}";
48+
return $"Good signature made by expired key.\n\nSigner: {Signer}\n\nKey: {Key}";
4849
case 'R':
49-
return $"Good signature made by a revoked key.\n\nKey: {Key}";
50+
return $"Good signature made by a revoked key.\n\nSigner: {Signer}\n\nKey: {Key}";
5051
case 'E':
51-
return $"Signature cannot be checked.\n\nKey: {Key}";
52+
return $"Signature cannot be checked.\n\nSigner: {Signer}\n\nKey: {Key}";
5253
default:
5354
return "No signature.";
5455
}

0 commit comments

Comments
 (0)