@@ -1143,6 +1143,145 @@ func (s *RepositorySuite) TestLogError(c *C) {
1143
1143
c .Assert (err , NotNil )
1144
1144
}
1145
1145
1146
+ func (s * RepositorySuite ) TestLogFileNext (c * C ) {
1147
+ r , _ := Init (memory .NewStorage (), nil )
1148
+ err := r .clone (context .Background (), & CloneOptions {
1149
+ URL : s .GetBasicLocalRepositoryURL (),
1150
+ })
1151
+
1152
+ c .Assert (err , IsNil )
1153
+
1154
+ fileName := "vendor/foo.go"
1155
+ cIter , err := r .Log (& LogOptions {FileName : & fileName })
1156
+
1157
+ c .Assert (err , IsNil )
1158
+
1159
+ commitOrder := []plumbing.Hash {
1160
+ plumbing .NewHash ("6ecf0ef2c2dffb796033e5a02219af86ec6584e5" ),
1161
+ }
1162
+
1163
+ for _ , o := range commitOrder {
1164
+ commit , err := cIter .Next ()
1165
+ c .Assert (err , IsNil )
1166
+ c .Assert (commit .Hash , Equals , o )
1167
+ }
1168
+ _ , err = cIter .Next ()
1169
+ c .Assert (err , Equals , io .EOF )
1170
+ }
1171
+
1172
+ func (s * RepositorySuite ) TestLogFileForEach (c * C ) {
1173
+ r , _ := Init (memory .NewStorage (), nil )
1174
+ err := r .clone (context .Background (), & CloneOptions {
1175
+ URL : s .GetBasicLocalRepositoryURL (),
1176
+ })
1177
+
1178
+ c .Assert (err , IsNil )
1179
+
1180
+ fileName := "php/crappy.php"
1181
+ cIter , err := r .Log (& LogOptions {FileName : & fileName })
1182
+
1183
+ c .Assert (err , IsNil )
1184
+
1185
+ commitOrder := []plumbing.Hash {
1186
+ plumbing .NewHash ("918c48b83bd081e863dbe1b80f8998f058cd8294" ),
1187
+ }
1188
+
1189
+ expectedIndex := 0
1190
+ cIter .ForEach (func (commit * object.Commit ) error {
1191
+ expectedCommitHash := commitOrder [expectedIndex ]
1192
+ c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
1193
+ expectedIndex += 1
1194
+ return nil
1195
+ })
1196
+ c .Assert (expectedIndex , Equals , 1 )
1197
+ }
1198
+
1199
+ func (s * RepositorySuite ) TestLogInvalidFile (c * C ) {
1200
+ r , _ := Init (memory .NewStorage (), nil )
1201
+ err := r .clone (context .Background (), & CloneOptions {
1202
+ URL : s .GetBasicLocalRepositoryURL (),
1203
+ })
1204
+ c .Assert (err , IsNil )
1205
+
1206
+ // Throwing in a file that does not exist
1207
+ fileName := "vendor/foo12.go"
1208
+ cIter , err := r .Log (& LogOptions {FileName : & fileName })
1209
+ // Not raising an error since `git log -- vendor/foo12.go` responds silently
1210
+ c .Assert (err , IsNil )
1211
+
1212
+ _ , err = cIter .Next ()
1213
+ c .Assert (err , Equals , io .EOF )
1214
+ }
1215
+
1216
+ func (s * RepositorySuite ) TestLogFileInitialCommit (c * C ) {
1217
+ r , _ := Init (memory .NewStorage (), nil )
1218
+ err := r .clone (context .Background (), & CloneOptions {
1219
+ URL : s .GetBasicLocalRepositoryURL (),
1220
+ })
1221
+ c .Assert (err , IsNil )
1222
+
1223
+ fileName := "LICENSE"
1224
+ cIter , err := r .Log (& LogOptions {
1225
+ Order : LogOrderCommitterTime ,
1226
+ FileName : & fileName ,
1227
+ })
1228
+
1229
+ c .Assert (err , IsNil )
1230
+
1231
+ commitOrder := []plumbing.Hash {
1232
+ plumbing .NewHash ("b029517f6300c2da0f4b651b8642506cd6aaf45d" ),
1233
+ }
1234
+
1235
+ expectedIndex := 0
1236
+ cIter .ForEach (func (commit * object.Commit ) error {
1237
+ expectedCommitHash := commitOrder [expectedIndex ]
1238
+ c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
1239
+ expectedIndex += 1
1240
+ return nil
1241
+ })
1242
+ c .Assert (expectedIndex , Equals , 1 )
1243
+ }
1244
+
1245
+ func (s * RepositorySuite ) TestLogFileWithOtherParamsFail (c * C ) {
1246
+ r , _ := Init (memory .NewStorage (), nil )
1247
+ err := r .clone (context .Background (), & CloneOptions {
1248
+ URL : s .GetBasicLocalRepositoryURL (),
1249
+ })
1250
+ c .Assert (err , IsNil )
1251
+
1252
+ fileName := "vendor/foo.go"
1253
+ cIter , err := r .Log (& LogOptions {
1254
+ Order : LogOrderCommitterTime ,
1255
+ FileName : & fileName ,
1256
+ From : plumbing .NewHash ("35e85108805c84807bc66a02d91535e1e24b38b9" ),
1257
+ })
1258
+ c .Assert (err , IsNil )
1259
+ _ , iterErr := cIter .Next ()
1260
+ c .Assert (iterErr , Equals , io .EOF )
1261
+ }
1262
+
1263
+ func (s * RepositorySuite ) TestLogFileWithOtherParamsPass (c * C ) {
1264
+ r , _ := Init (memory .NewStorage (), nil )
1265
+ err := r .clone (context .Background (), & CloneOptions {
1266
+ URL : s .GetBasicLocalRepositoryURL (),
1267
+ })
1268
+ c .Assert (err , IsNil )
1269
+
1270
+ fileName := "LICENSE"
1271
+ cIter , err := r .Log (& LogOptions {
1272
+ Order : LogOrderCommitterTime ,
1273
+ FileName : & fileName ,
1274
+ From : plumbing .NewHash ("35e85108805c84807bc66a02d91535e1e24b38b9" ),
1275
+ })
1276
+ c .Assert (err , IsNil )
1277
+ commitVal , iterErr := cIter .Next ()
1278
+ c .Assert (iterErr , Equals , nil )
1279
+ c .Assert (commitVal .Hash .String (), Equals , "b029517f6300c2da0f4b651b8642506cd6aaf45d" )
1280
+
1281
+ _ , iterErr = cIter .Next ()
1282
+ c .Assert (iterErr , Equals , io .EOF )
1283
+ }
1284
+
1146
1285
func (s * RepositorySuite ) TestCommit (c * C ) {
1147
1286
r , _ := Init (memory .NewStorage (), nil )
1148
1287
err := r .clone (context .Background (), & CloneOptions {
0 commit comments