@@ -14,6 +14,8 @@ import (
1414 "testing"
1515 "time"
1616
17+ fixtures "gopkg.in/src-d/go-git-fixtures.v3"
18+
1719 "golang.org/x/crypto/openpgp"
1820 "golang.org/x/crypto/openpgp/armor"
1921 openpgperr "golang.org/x/crypto/openpgp/errors"
@@ -32,7 +34,6 @@ import (
3234 "gopkg.in/src-d/go-billy.v4/memfs"
3335 "gopkg.in/src-d/go-billy.v4/osfs"
3436 "gopkg.in/src-d/go-billy.v4/util"
35- "gopkg.in/src-d/go-git-fixtures.v3"
3637)
3738
3839type RepositorySuite struct {
@@ -1675,6 +1676,135 @@ func (s *RepositorySuite) TestLogFileWithError(c *C) {
16751676 c .Assert (err , NotNil )
16761677}
16771678
1679+ func (s * RepositorySuite ) TestLogLimitNext (c * C ) {
1680+ r , _ := Init (memory .NewStorage (), nil )
1681+ err := r .clone (context .Background (), & CloneOptions {
1682+ URL : s .GetBasicLocalRepositoryURL (),
1683+ })
1684+
1685+ c .Assert (err , IsNil )
1686+
1687+ since := time .Date (2015 , 4 , 1 , 0 , 0 , 0 , 0 , time .UTC )
1688+ cIter , err := r .Log (& LogOptions {Since : & since })
1689+
1690+ c .Assert (err , IsNil )
1691+
1692+ commitOrder := []plumbing.Hash {
1693+ plumbing .NewHash ("6ecf0ef2c2dffb796033e5a02219af86ec6584e5" ),
1694+ }
1695+
1696+ for _ , o := range commitOrder {
1697+ commit , err := cIter .Next ()
1698+ c .Assert (err , IsNil )
1699+ c .Assert (commit .Hash , Equals , o )
1700+ }
1701+ _ , err = cIter .Next ()
1702+ c .Assert (err , Equals , io .EOF )
1703+ }
1704+
1705+ func (s * RepositorySuite ) TestLogLimitForEach (c * C ) {
1706+ r , _ := Init (memory .NewStorage (), nil )
1707+ err := r .clone (context .Background (), & CloneOptions {
1708+ URL : s .GetBasicLocalRepositoryURL (),
1709+ })
1710+
1711+ c .Assert (err , IsNil )
1712+
1713+ since := time .Date (2015 , 3 , 31 , 11 , 54 , 0 , 0 , time .UTC )
1714+ until := time .Date (2015 , 4 , 1 , 0 , 0 , 0 , 0 , time .UTC )
1715+ cIter , err := r .Log (& LogOptions {Since : & since , Until : & until })
1716+ c .Assert (err , IsNil )
1717+ defer cIter .Close ()
1718+
1719+ commitOrder := []plumbing.Hash {
1720+ plumbing .NewHash ("918c48b83bd081e863dbe1b80f8998f058cd8294" ),
1721+ }
1722+
1723+ expectedIndex := 0
1724+ err = cIter .ForEach (func (commit * object.Commit ) error {
1725+ expectedCommitHash := commitOrder [expectedIndex ]
1726+ c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
1727+ expectedIndex ++
1728+ return nil
1729+ })
1730+ c .Assert (err , IsNil )
1731+ c .Assert (expectedIndex , Equals , 1 )
1732+ }
1733+
1734+ func (s * RepositorySuite ) TestLogAllLimitForEach (c * C ) {
1735+ r , _ := Init (memory .NewStorage (), nil )
1736+ err := r .clone (context .Background (), & CloneOptions {
1737+ URL : s .GetBasicLocalRepositoryURL (),
1738+ })
1739+
1740+ c .Assert (err , IsNil )
1741+
1742+ since := time .Date (2015 , 3 , 31 , 11 , 54 , 0 , 0 , time .UTC )
1743+ until := time .Date (2015 , 4 , 1 , 0 , 0 , 0 , 0 , time .UTC )
1744+ cIter , err := r .Log (& LogOptions {Since : & since , Until : & until , All : true })
1745+ c .Assert (err , IsNil )
1746+ defer cIter .Close ()
1747+
1748+ commitOrder := []plumbing.Hash {
1749+ plumbing .NewHash ("e8d3ffab552895c19b9fcf7aa264d277cde33881" ),
1750+ plumbing .NewHash ("918c48b83bd081e863dbe1b80f8998f058cd8294" ),
1751+ }
1752+
1753+ expectedIndex := 0
1754+ err = cIter .ForEach (func (commit * object.Commit ) error {
1755+ expectedCommitHash := commitOrder [expectedIndex ]
1756+ c .Assert (commit .Hash .String (), Equals , expectedCommitHash .String ())
1757+ expectedIndex ++
1758+ return nil
1759+ })
1760+ c .Assert (err , IsNil )
1761+ c .Assert (expectedIndex , Equals , 2 )
1762+ }
1763+
1764+ func (s * RepositorySuite ) TestLogLimitWithOtherParamsFail (c * C ) {
1765+ r , _ := Init (memory .NewStorage (), nil )
1766+ err := r .clone (context .Background (), & CloneOptions {
1767+ URL : s .GetBasicLocalRepositoryURL (),
1768+ })
1769+ c .Assert (err , IsNil )
1770+
1771+ since := time .Date (2015 , 3 , 31 , 11 , 54 , 0 , 0 , time .UTC )
1772+ cIter , err := r .Log (& LogOptions {
1773+ Order : LogOrderCommitterTime ,
1774+ Since : & since ,
1775+ From : plumbing .NewHash ("35e85108805c84807bc66a02d91535e1e24b38b9" ),
1776+ })
1777+ c .Assert (err , IsNil )
1778+ defer cIter .Close ()
1779+
1780+ _ , iterErr := cIter .Next ()
1781+ c .Assert (iterErr , Equals , io .EOF )
1782+ }
1783+
1784+ func (s * RepositorySuite ) TestLogLimitWithOtherParamsPass (c * C ) {
1785+ r , _ := Init (memory .NewStorage (), nil )
1786+ err := r .clone (context .Background (), & CloneOptions {
1787+ URL : s .GetBasicLocalRepositoryURL (),
1788+ })
1789+ c .Assert (err , IsNil )
1790+
1791+ until := time .Date (2015 , 3 , 31 , 11 , 43 , 0 , 0 , time .UTC )
1792+ cIter , err := r .Log (& LogOptions {
1793+ Order : LogOrderCommitterTime ,
1794+ Until : & until ,
1795+ From : plumbing .NewHash ("35e85108805c84807bc66a02d91535e1e24b38b9" ),
1796+ })
1797+ c .Assert (err , IsNil )
1798+ defer cIter .Close ()
1799+
1800+ commitVal , iterErr := cIter .Next ()
1801+ c .Assert (iterErr , Equals , nil )
1802+ c .Assert (commitVal .Hash .String (), Equals , "b029517f6300c2da0f4b651b8642506cd6aaf45d" )
1803+
1804+ _ , iterErr = cIter .Next ()
1805+ c .Assert (iterErr , Equals , io .EOF )
1806+ }
1807+
16781808func (s * RepositorySuite ) TestCommit (c * C ) {
16791809 r , _ := Init (memory .NewStorage (), nil )
16801810 err := r .clone (context .Background (), & CloneOptions {
0 commit comments