@@ -6,6 +6,7 @@ package git
6
6
7
7
import (
8
8
"path/filepath"
9
+ "strings"
9
10
"testing"
10
11
11
12
"github.com/stretchr/testify/assert"
@@ -36,3 +37,71 @@ func TestGetFullCommitIDError(t *testing.T) {
36
37
assert .EqualError (t , err , "object does not exist [id: unknown, rel_path: ]" )
37
38
}
38
39
}
40
+
41
+ func TestCommitFromReader (t * testing.T ) {
42
+ commitString := `feaf4ba6bc635fec442f46ddd4512416ec43c2c2 commit 1074
43
+ tree f1a6cb52b2d16773290cefe49ad0684b50a4f930
44
+ parent 37991dec2c8e592043f47155ce4808d4580f9123
45
+ author silverwind <[email protected] > 1563741793 +0200
46
+ committer silverwind <[email protected] > 1563741793 +0200
47
+ gpgsig -----BEGIN PGP SIGNATURE-----
48
+ ` + " " + `
49
+ iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG
50
+ lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK
51
+ xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld
52
+ vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg
53
+ R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6
54
+ FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ
55
+ /maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL
56
+ S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm
57
+ sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm
58
+ 1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb
59
+ mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i
60
+ 1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs=
61
+ =FRsO
62
+ -----END PGP SIGNATURE-----
63
+
64
+ empty commit`
65
+
66
+ sha := SHA1 {0xfe , 0xaf , 0x4b , 0xa6 , 0xbc , 0x63 , 0x5f , 0xec , 0x44 , 0x2f , 0x46 , 0xdd , 0xd4 , 0x51 , 0x24 , 0x16 , 0xec , 0x43 , 0xc2 , 0xc2 }
67
+ gitRepo , err := OpenRepository (filepath .Join (testReposDir , "repo1_bare" ))
68
+ assert .NoError (t , err )
69
+ assert .NotNil (t , gitRepo )
70
+
71
+ commitFromReader , err := CommitFromReader (gitRepo , sha , strings .NewReader (commitString ))
72
+ assert .NoError (t , err )
73
+ if ! assert .NotNil (t , commitFromReader ) {
74
+ return
75
+ }
76
+ assert .EqualValues (t , sha , commitFromReader .ID )
77
+ assert .EqualValues (t , `-----BEGIN PGP SIGNATURE-----
78
+
79
+ iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG
80
+ lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK
81
+ xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld
82
+ vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg
83
+ R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6
84
+ FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ
85
+ /maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL
86
+ S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm
87
+ sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm
88
+ 1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb
89
+ mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i
90
+ 1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs=
91
+ =FRsO
92
+ -----END PGP SIGNATURE-----
93
+ ` , commitFromReader .Signature .Signature )
94
+ assert .EqualValues (t , `tree f1a6cb52b2d16773290cefe49ad0684b50a4f930
95
+ parent 37991dec2c8e592043f47155ce4808d4580f9123
96
+ author silverwind <[email protected] > 1563741793 +0200
97
+ committer silverwind <[email protected] > 1563741793 +0200
98
+
99
+ empty commit` , commitFromReader .Signature .Payload )
100
+ assert .
EqualValues (
t ,
"silverwind <[email protected] >" ,
commitFromReader .
Author .
String ())
101
+
102
+ commitFromReader2 , err := CommitFromReader (gitRepo , sha , strings .NewReader (commitString + "\n \n " ))
103
+ assert .NoError (t , err )
104
+ commitFromReader .CommitMessage += "\n \n "
105
+ commitFromReader .Signature .Payload += "\n \n "
106
+ assert .EqualValues (t , commitFromReader , commitFromReader2 )
107
+ }
0 commit comments