Skip to content

Commit 3b451d5

Browse files
committed
Fix PGP signature verification.
Signed-off-by: Filip Navara <[email protected]>
1 parent a7872d4 commit 3b451d5

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

modules/git/commit_info.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package git
66

77
import (
8+
"fmt"
9+
"strings"
10+
811
"gopkg.in/src-d/go-git.v4/plumbing"
912
"gopkg.in/src-d/go-git.v4/plumbing/object"
1013
"gopkg.in/src-d/go-git.v4/plumbing/storer"
@@ -43,21 +46,57 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
4346
return commitsInfo, convertCommit(treeCommit), nil
4447
}
4548

46-
func convertCommit(c *object.Commit) *Commit {
47-
var pgpSignaure *CommitGPGSignature
48-
if c.PGPSignature != "" {
49-
pgpSignaure = &CommitGPGSignature{
50-
Signature: c.PGPSignature,
51-
Payload: c.Message, // FIXME: This is not correct
49+
func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
50+
if c.PGPSignature == "" {
51+
return nil
52+
}
53+
54+
var w strings.Builder
55+
var err error
56+
57+
if _, err = fmt.Fprintf(&w, "tree %s\n", c.TreeHash.String()); err != nil {
58+
return nil
59+
}
60+
61+
for _, parent := range c.ParentHashes {
62+
if _, err = fmt.Fprintf(&w, "parent %s\n", parent.String()); err != nil {
63+
return nil
5264
}
5365
}
5466

67+
if _, err = fmt.Fprint(&w, "author "); err != nil {
68+
return nil
69+
}
70+
71+
if err = c.Author.Encode(&w); err != nil {
72+
return nil
73+
}
74+
75+
if _, err = fmt.Fprint(&w, "\ncommitter "); err != nil {
76+
return nil
77+
}
78+
79+
if err = c.Committer.Encode(&w); err != nil {
80+
return nil
81+
}
82+
83+
if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
84+
return nil
85+
}
86+
87+
return &CommitGPGSignature{
88+
Signature: c.PGPSignature,
89+
Payload: w.String(),
90+
}
91+
}
92+
93+
func convertCommit(c *object.Commit) *Commit {
5594
return &Commit{
5695
ID: c.Hash,
5796
CommitMessage: c.Message,
5897
Committer: &c.Committer,
5998
Author: &c.Author,
60-
Signature: pgpSignaure,
99+
Signature: convertPGPSignature(c),
61100
parents: c.ParentHashes,
62101
}
63102
}

0 commit comments

Comments
 (0)