diff options
author | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-04-10 16:48:40 +0200 |
---|---|---|
committer | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-04-11 11:22:45 +0200 |
commit | be8d19438ada078a8598e366ab74aa09e4c521cd (patch) | |
tree | d9edb36326016ea35d38f68810e9ce70e538e7a0 /repository_test.go | |
parent | 3daede53835e8572b2957a016f068781db646567 (diff) | |
download | go-git-be8d19438ada078a8598e366ab74aa09e4c521cd.tar.gz |
Add Repository.Log() method (fix #298)
- CommitIter is now an interface
- The old CommitIter implementation is now called StorerCommitIter
- CommitWalker and CommitWalkerPost are now iterators (CommitPreIterator and CommitPostIterator).
- Remove Commit.History() method. There are so many ways to iterate a commit history, depending of the use case. Now, instead of use the History() method, you must use CommitPreIterator or CommitPostIterator.
- Move commitSorterer to references.go because is the only place that it is used, and it must not be used into another place.
- Make References method private, it must only be used into blame logic.
- Added a TODO into references method, where the sortCommits is used to remove it in a near future.
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go index 352ff21..77bfde2 100644 --- a/repository_test.go +++ b/repository_test.go @@ -3,6 +3,7 @@ package git import ( "bytes" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -688,6 +689,80 @@ func (s *RepositorySuite) TestPushNonExistentRemote(c *C) { c.Assert(err, ErrorMatches, ".*remote not found.*") } +func (s *RepositorySuite) TestLog(c *C) { + r, _ := Init(memory.NewStorage(), nil) + err := r.clone(&CloneOptions{ + URL: s.GetBasicLocalRepositoryURL(), + }) + + c.Assert(err, IsNil) + + cIter, err := r.Log(&LogOptions{ + plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"), + }) + + c.Assert(err, IsNil) + + commitOrder := []plumbing.Hash{ + plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"), + plumbing.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"), + } + + for _, o := range commitOrder { + commit, err := cIter.Next() + c.Assert(err, IsNil) + c.Assert(commit.Hash, Equals, o) + } + _, err = cIter.Next() + c.Assert(err, Equals, io.EOF) +} + +func (s *RepositorySuite) TestLogHead(c *C) { + r, _ := Init(memory.NewStorage(), nil) + err := r.clone(&CloneOptions{ + URL: s.GetBasicLocalRepositoryURL(), + }) + + c.Assert(err, IsNil) + + cIter, err := r.Log(&LogOptions{}) + + c.Assert(err, IsNil) + + commitOrder := []plumbing.Hash{ + plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), + plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"), + plumbing.NewHash("af2d6a6954d532f8ffb47615169c8fdf9d383a1a"), + plumbing.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea"), + plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"), + plumbing.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d"), + plumbing.NewHash("a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69"), + plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"), + } + + for _, o := range commitOrder { + commit, err := cIter.Next() + c.Assert(err, IsNil) + c.Assert(commit.Hash, Equals, o) + } + _, err = cIter.Next() + c.Assert(err, Equals, io.EOF) +} + +func (s *RepositorySuite) TestLogError(c *C) { + r, _ := Init(memory.NewStorage(), nil) + err := r.clone(&CloneOptions{ + URL: s.GetBasicLocalRepositoryURL(), + }) + + c.Assert(err, IsNil) + + _, err = r.Log(&LogOptions{ + plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), + }) + c.Assert(err, NotNil) +} + func (s *RepositorySuite) TestCommit(c *C) { r, _ := Init(memory.NewStorage(), nil) err := r.clone(&CloneOptions{ |