@@ -238,6 +238,65 @@ func TestCommitDecodingMultilineHeader(t *testing.T) {
238238 strings .Split (hdr .V , "\n " ))
239239}
240240
241+ func TestCommitDecodingMessageWithLineStartingWithTree (t * testing.T ) {
242+ from := new (bytes.Buffer )
243+
244+ // The tricky part here that we're testing is the "tree support" in the
245+ // `mergetag` header, which we should not try to parse as a tree header.
246+ // Note also that this entry contains trailing whitespace which must not
247+ // be trimmed.
248+ fmt .Fprintf (from , `tree e8ad84c41c2acde27c77fa212b8865cd3acfe6fb
249+ parent b343c8beec664ef6f0e9964d3001c7c7966331ae
250+ parent 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
251+ author Pat Doe <pdoe@example.org> 1337892984 -0700
252+ committer Pat Doe <pdoe@example.org> 1337892984 -0700
253+ mergetag object 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
254+ type commit
255+ tag random
256+ tagger J. Roe <jroe@example.ca> 1337889148 -0600
257+
258+ Random changes
259+
260+ This text contains some
261+ tree support code.
262+ -----BEGIN PGP SIGNATURE-----
263+ Version: GnuPG v1.4.11 (GNU/Linux)
264+
265+ Not a real signature
266+ -----END PGP SIGNATURE-----
267+
268+ Merge tag 'random' of git://git.example.ca/git/
269+ ` )
270+
271+ flen := from .Len ()
272+
273+ commit := new (Commit )
274+ n , err := commit .Decode (sha1 .New (), from , int64 (flen ))
275+
276+ require .Nil (t , err )
277+ require .Equal (t , flen , n )
278+ require .Equal (t , commit .ExtraHeaders , []* ExtraHeader {
279+ {
280+ K : "mergetag" ,
281+ V : `object 1e8a52e18cfb381bc9cc1f0b720540364d2a6edd
282+ type commit
283+ tag random
284+ tagger J. Roe <jroe@example.ca> 1337889148 -0600
285+
286+ Random changes
287+
288+ This text contains some
289+ tree support code.
290+ -----BEGIN PGP SIGNATURE-----
291+ Version: GnuPG v1.4.11 (GNU/Linux)
292+
293+ Not a real signature
294+ -----END PGP SIGNATURE-----` },
295+ },
296+ )
297+ require .Equal (t , commit .Message , "Merge tag 'random' of git://git.example.ca/git/" )
298+ }
299+
241300func assertLine (t * testing.T , buf * bytes.Buffer , wanted string , args ... interface {}) {
242301 got , err := buf .ReadString ('\n' )
243302 if err == io .EOF {
0 commit comments