Codebase list golang-github-git-lfs-gitobj / 3be1355
New upstream version 2.1.1 Stephen Gelman 1 year, 5 months ago
2 changed file(s) with 62 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
106106 continue
107107 }
108108
109 if fields := strings.Fields(text); !finishedHeaders {
109 if fields := strings.Split(text, " "); !finishedHeaders {
110110 if len(fields) == 0 {
111111 // Executing in this block means that we got a
112112 // whitespace-only line, while parsing a header.
122122 case "tree":
123123 id, err := hex.DecodeString(fields[1])
124124 if err != nil {
125 return n, err
125 return n, fmt.Errorf("error parsing tree: %s", err)
126126 }
127127 c.TreeID = id
128128 case "parent":
129129 id, err := hex.DecodeString(fields[1])
130130 if err != nil {
131 return n, err
131 return n, fmt.Errorf("error parsing parent: %s", err)
132132 }
133133 c.ParentIDs = append(c.ParentIDs, id)
134134 case "author":
237237 strings.Split(hdr.V, "\n"))
238238 }
239239
240 func TestCommitDecodingMessageWithLineStartingWithTree(t *testing.T) {
241 from := new(bytes.Buffer)
242
243 // The tricky part here that we're testing is the "tree support" in the
244 // `mergetag` header, which we should not try to parse as a tree header.
245 // Note also that this entry contains trailing whitespace which must not
246 // be trimmed.
247 fmt.Fprintf(from, `tree e8ad84c41c2acde27c77fa212b8865cd3acfe6fb
248 parent b343c8beec664ef6f0e9964d3001c7c7966331ae
249 parent 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
250 author Pat Doe <pdoe@example.org> 1337892984 -0700
251 committer Pat Doe <pdoe@example.org> 1337892984 -0700
252 mergetag object 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
253 type commit
254 tag random
255 tagger J. Roe <jroe@example.ca> 1337889148 -0600
256
257 Random changes
258
259 This text contains some
260 tree support code.
261 -----BEGIN PGP SIGNATURE-----
262 Version: GnuPG v1.4.11 (GNU/Linux)
263
264 Not a real signature
265 -----END PGP SIGNATURE-----
266
267 Merge tag 'random' of git://git.example.ca/git/
268 `)
269
270 flen := from.Len()
271
272 commit := new(Commit)
273 n, err := commit.Decode(sha1.New(), from, int64(flen))
274
275 require.Nil(t, err)
276 require.Equal(t, flen, n)
277 require.Equal(t, commit.ExtraHeaders, []*ExtraHeader{
278 {
279 K: "mergetag",
280 V: `object 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
281 type commit
282 tag random
283 tagger J. Roe <jroe@example.ca> 1337889148 -0600
284
285 Random changes
286
287 This text contains some
288 tree support code.
289 -----BEGIN PGP SIGNATURE-----
290 Version: GnuPG v1.4.11 (GNU/Linux)
291
292 Not a real signature
293 -----END PGP SIGNATURE-----`},
294 },
295 )
296 require.Equal(t, commit.Message, "Merge tag 'random' of git://git.example.ca/git/")
297 }
298
240299 func assertLine(t *testing.T, buf *bytes.Buffer, wanted string, args ...interface{}) {
241300 got, err := buf.ReadString('\n')
242301 if err == io.EOF {