@@ -10,6 +10,7 @@ import (
1010 "time"
1111
1212 "github.com/stretchr/testify/assert"
13+ "github.com/stretchr/testify/require"
1314)
1415
1516func TestCommitReturnsCorrectObjectType (t * testing.T ) {
@@ -20,6 +21,8 @@ func TestCommitEncoding(t *testing.T) {
2021 author := & Signature {Name : "John Doe" , Email : "john@example.com" , When : time .Now ()}
2122 committer := & Signature {Name : "Jane Doe" , Email : "jane@example.com" , When : time .Now ()}
2223
24+ sig := "-----BEGIN PGP SIGNATURE-----\n <signature>\n -----END PGP SIGNATURE-----"
25+
2326 c := & Commit {
2427 Author : author .String (),
2528 Committer : committer .String (),
@@ -29,6 +32,7 @@ func TestCommitEncoding(t *testing.T) {
2932 TreeID : []byte ("cccccccccccccccccccc" ),
3033 ExtraHeaders : []* ExtraHeader {
3134 {"foo" , "bar" },
35+ {"gpgsig" , sig },
3236 },
3337 Message : "initial commit" ,
3438 }
@@ -44,6 +48,9 @@ func TestCommitEncoding(t *testing.T) {
4448 assertLine (t , buf , "author %s" , author .String ())
4549 assertLine (t , buf , "committer %s" , committer .String ())
4650 assertLine (t , buf , "foo bar" )
51+ assertLine (t , buf , "gpgsig -----BEGIN PGP SIGNATURE-----" )
52+ assertLine (t , buf , " <signature>" )
53+ assertLine (t , buf , " -----END PGP SIGNATURE-----" )
4754 assertLine (t , buf , "" )
4855 assertLine (t , buf , "initial commit" )
4956
@@ -164,6 +171,41 @@ func TestCommitDecodingWithWhitespace(t *testing.T) {
164171 assert .Equal (t , "tree <- initial commit" , commit .Message )
165172}
166173
174+ func TestCommitDecodingMultilineHeader (t * testing.T ) {
175+ author := & Signature {Name : "" , Email : "john@example.com" , When : time .Now ()}
176+ committer := & Signature {Name : "" , Email : "jane@example.com" , When : time .Now ()}
177+
178+ treeId := []byte ("cccccccccccccccccccc" )
179+
180+ from := new (bytes.Buffer )
181+
182+ fmt .Fprintf (from , "author %s\n " , author )
183+ fmt .Fprintf (from , "committer %s\n " , committer )
184+ fmt .Fprintf (from , "tree %s\n " , hex .EncodeToString (treeId ))
185+ fmt .Fprintf (from , "gpgsig -----BEGIN PGP SIGNATURE-----\n " )
186+ fmt .Fprintf (from , " <signature>\n " )
187+ fmt .Fprintf (from , " -----END PGP SIGNATURE-----\n " )
188+ fmt .Fprintf (from , "\n initial commit\n " )
189+
190+ flen := from .Len ()
191+
192+ commit := new (Commit )
193+ n , err := commit .Decode (from , int64 (flen ))
194+
195+ require .Nil (t , err )
196+ require .Equal (t , flen , n )
197+ require .Len (t , commit .ExtraHeaders , 1 )
198+
199+ hdr := commit .ExtraHeaders [0 ]
200+
201+ assert .Equal (t , "gpgsig" , hdr .K )
202+ assert .EqualValues (t , []string {
203+ "-----BEGIN PGP SIGNATURE-----" ,
204+ "<signature>" ,
205+ "-----END PGP SIGNATURE-----" },
206+ strings .Split (hdr .V , "\n " ))
207+ }
208+
167209func assertLine (t * testing.T , buf * bytes.Buffer , wanted string , args ... interface {}) {
168210 got , err := buf .ReadString ('\n' )
169211 if err == io .EOF {
0 commit comments