Skip to content

Commit ec3d2a8

Browse files
committed
plumbing: object, Don't add new line at end of commit signature
The way that commit signatures were being written out was causing an extra newline to be written at the end of the commit when the message encoding was already taking care of this. Ultimately, this results in a corrupt object, rendering the object unverifiable with the signature in the commit. Signed-off-by: Chris Marchesi <[email protected]>
1 parent a28c2ce commit ec3d2a8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

plumbing/object/commit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,18 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
263263
}
264264

265265
if b.PGPSignature != "" && includeSig {
266-
if _, err = fmt.Fprint(w, "\n"+headerpgp); err != nil {
266+
if _, err = fmt.Fprint(w, "\n"+headerpgp+" "); err != nil {
267267
return err
268268
}
269269

270-
// Split all the signature lines and write with a left padding and
271-
// newline at the end.
270+
// Split all the signature lines and re-write with a left padding and
271+
// newline. Use join for this so it's clear that a newline should not be
272+
// added after this section, as it will be added when the message is
273+
// printed.
272274
signature := strings.TrimSuffix(b.PGPSignature, "\n")
273275
lines := strings.Split(signature, "\n")
274-
for _, line := range lines {
275-
if _, err = fmt.Fprintf(w, " %s\n", line); err != nil {
276-
return err
277-
}
276+
if _, err = fmt.Fprint(w, strings.Join(lines, "\n ")); err != nil {
277+
return err
278278
}
279279
}
280280

0 commit comments

Comments
 (0)