@@ -17,8 +17,9 @@ import (
17
17
)
18
18
19
19
const (
20
- beginpgp string = "-----BEGIN PGP SIGNATURE-----"
21
- endpgp string = "-----END PGP SIGNATURE-----"
20
+ beginpgp string = "-----BEGIN PGP SIGNATURE-----"
21
+ endpgp string = "-----END PGP SIGNATURE-----"
22
+ headerpgp string = "gpgsig"
22
23
)
23
24
24
25
// Hash represents the hash of an object
@@ -181,23 +182,13 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
181
182
}
182
183
183
184
if pgpsig {
184
- // Check if it's the end of a PGP signature.
185
- if bytes .Contains (line , []byte (endpgp )) {
186
- c .PGPSignature += endpgp + "\n "
187
- pgpsig = false
188
- } else {
189
- // Trim the left padding.
185
+ if len (line ) > 0 && line [0 ] == ' ' {
190
186
line = bytes .TrimLeft (line , " " )
191
187
c .PGPSignature += string (line )
188
+ continue
189
+ } else {
190
+ pgpsig = false
192
191
}
193
- continue
194
- }
195
-
196
- // Check if it's the beginning of a PGP signature.
197
- if bytes .Contains (line , []byte (beginpgp )) {
198
- c .PGPSignature += beginpgp + "\n "
199
- pgpsig = true
200
- continue
201
192
}
202
193
203
194
if ! message {
@@ -217,6 +208,9 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
217
208
c .Author .Decode (split [1 ])
218
209
case "committer" :
219
210
c .Committer .Decode (split [1 ])
211
+ case headerpgp :
212
+ c .PGPSignature += string (split [1 ]) + "\n "
213
+ pgpsig = true
220
214
}
221
215
} else {
222
216
c .Message += string (line )
@@ -269,13 +263,14 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
269
263
}
270
264
271
265
if b .PGPSignature != "" && includeSig {
272
- if _ , err = fmt .Fprint (w , "pgpsig" ); err != nil {
266
+ if _ , err = fmt .Fprint (w , "\n " + headerpgp ); err != nil {
273
267
return err
274
268
}
275
269
276
270
// Split all the signature lines and write with a left padding and
277
271
// newline at the end.
278
- lines := strings .Split (b .PGPSignature , "\n " )
272
+ signature := strings .TrimSuffix (b .PGPSignature , "\n " )
273
+ lines := strings .Split (signature , "\n " )
279
274
for _ , line := range lines {
280
275
if _ , err = fmt .Fprintf (w , " %s\n " , line ); err != nil {
281
276
return err
0 commit comments