Skip to content

Commit e0378b2

Browse files
committed
repository_test.go: add TestLogPathFilterRegexp
Signed-off-by: Saeed Rasooli <[email protected]>
1 parent 224f047 commit e0378b2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

repository_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,42 @@ func (s *RepositorySuite) TestLogPathRegexpWithError(c *C) {
16941694
c.Assert(err, NotNil)
16951695
}
16961696

1697+
func (s *RepositorySuite) TestLogPathFilterRegexp(c *C) {
1698+
pathRE := regexp.MustCompile(".*\\.go")
1699+
pathIter := func(path string) bool {
1700+
return pathRE.MatchString(path)
1701+
}
1702+
1703+
r, _ := Init(memory.NewStorage(), nil)
1704+
err := r.clone(context.Background(), &CloneOptions{
1705+
URL: s.GetBasicLocalRepositoryURL(),
1706+
})
1707+
c.Assert(err, IsNil)
1708+
1709+
expectedCommitIDs := []string{
1710+
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
1711+
"918c48b83bd081e863dbe1b80f8998f058cd8294",
1712+
}
1713+
commitIDs := []string{}
1714+
1715+
cIter, err := r.Log(&LogOptions{
1716+
PathFilter: pathIter,
1717+
From: plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
1718+
})
1719+
c.Assert(err, IsNil)
1720+
defer cIter.Close()
1721+
1722+
cIter.ForEach(func(commit *object.Commit) error {
1723+
commitIDs = append(commitIDs, commit.ID().String())
1724+
return nil
1725+
})
1726+
c.Assert(
1727+
strings.Join(commitIDs, ", "),
1728+
Equals,
1729+
strings.Join(expectedCommitIDs, ", "),
1730+
)
1731+
}
1732+
16971733
func (s *RepositorySuite) TestLogLimitNext(c *C) {
16981734
r, _ := Init(memory.NewStorage(), nil)
16991735
err := r.clone(context.Background(), &CloneOptions{

0 commit comments

Comments
 (0)