Skip to content

Commit c2e7ae1

Browse files
committed
commit.go: parse whitespace-only lines during continuations
When parsing an extra header that is continued over multiple lines, an earlier check on the length of whitespace-separated fields caused the loop to terminate early, dropping continuation lines that consist only of whitespace. Tweak the logic slightly in order to capture these, and allow us to successfully round-trip commit parsing.
1 parent 930b3ff commit c2e7ae1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

commit.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ func (c *Commit) Decode(from io.Reader, size int64) (n int, err error) {
105105
continue
106106
}
107107

108-
if fields := strings.Fields(text); len(fields) > 0 && !finishedHeaders {
108+
if fields := strings.Fields(text); !finishedHeaders {
109+
if len(fields) == 0 {
110+
// Executing in this block means that we got a
111+
// whitespace-only line, while parsing a header.
112+
//
113+
// Append it to the last-parsed header, and
114+
// continue.
115+
c.ExtraHeaders[len(c.ExtraHeaders)-1].V +=
116+
fmt.Sprintf("\n%s", text[1:])
117+
continue
118+
}
119+
109120
switch fields[0] {
110121
case "tree":
111122
id, err := hex.DecodeString(fields[1])

0 commit comments

Comments
 (0)