@@ -3,6 +3,7 @@ package git
33import (
44 "bytes"
55 "context"
6+ "errors"
67 "fmt"
78 "io"
89 "io/ioutil"
@@ -1507,12 +1508,13 @@ func (s *RepositorySuite) TestLogFileForEach(c *C) {
15071508 }
15081509
15091510 expectedIndex := 0
1510- cIter .ForEach (func (commit * object.Commit ) error {
1511+ err = cIter .ForEach (func (commit * object.Commit ) error {
15111512 expectedCommitHash := commitOrder [expectedIndex ]
15121513 c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
15131514 expectedIndex ++
15141515 return nil
15151516 })
1517+ c .Assert (err , IsNil )
15161518 c .Assert (expectedIndex , Equals , 1 )
15171519}
15181520
@@ -1551,12 +1553,13 @@ func (s *RepositorySuite) TestLogAllFileForEach(c *C) {
15511553 }
15521554
15531555 expectedIndex := 0
1554- cIter .ForEach (func (commit * object.Commit ) error {
1556+ err = cIter .ForEach (func (commit * object.Commit ) error {
15551557 expectedCommitHash := commitOrder [expectedIndex ]
15561558 c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
15571559 expectedIndex ++
15581560 return nil
15591561 })
1562+ c .Assert (err , IsNil )
15601563 c .Assert (expectedIndex , Equals , 1 )
15611564}
15621565
@@ -1598,12 +1601,13 @@ func (s *RepositorySuite) TestLogFileInitialCommit(c *C) {
15981601 }
15991602
16001603 expectedIndex := 0
1601- cIter .ForEach (func (commit * object.Commit ) error {
1604+ err = cIter .ForEach (func (commit * object.Commit ) error {
16021605 expectedCommitHash := commitOrder [expectedIndex ]
16031606 c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
16041607 expectedIndex ++
16051608 return nil
16061609 })
1610+ c .Assert (err , IsNil )
16071611 c .Assert (expectedIndex , Equals , 1 )
16081612}
16091613
@@ -1649,6 +1653,28 @@ func (s *RepositorySuite) TestLogFileWithOtherParamsPass(c *C) {
16491653 c .Assert (iterErr , Equals , io .EOF )
16501654}
16511655
1656+ type mockErrCommitIter struct {}
1657+
1658+ func (m * mockErrCommitIter ) Next () (* object.Commit , error ) {
1659+ return nil , errors .New ("mock next error" )
1660+ }
1661+ func (m * mockErrCommitIter ) ForEach (func (* object.Commit ) error ) error {
1662+ return errors .New ("mock foreach error" )
1663+ }
1664+
1665+ func (m * mockErrCommitIter ) Close () {}
1666+
1667+ func (s * RepositorySuite ) TestLogFileWithError (c * C ) {
1668+ fileName := "README"
1669+ cIter := object .NewCommitFileIterFromIter (fileName , & mockErrCommitIter {}, false )
1670+ defer cIter .Close ()
1671+
1672+ err := cIter .ForEach (func (commit * object.Commit ) error {
1673+ return nil
1674+ })
1675+ c .Assert (err , NotNil )
1676+ }
1677+
16521678func (s * RepositorySuite ) TestCommit (c * C ) {
16531679 r , _ := Init (memory .NewStorage (), nil )
16541680 err := r .clone (context .Background (), & CloneOptions {
0 commit comments