diff options
author | Antonio Jesus Navarro Perez <antnavper@gmail.com> | 2019-02-12 15:57:50 +0100 |
---|---|---|
committer | Antonio Jesus Navarro Perez <antnavper@gmail.com> | 2019-02-12 17:09:04 +0100 |
commit | 6c2a0daafcd6c8f3f695c8b7a2c881d3abc276b1 (patch) | |
tree | 68de2b80ea57b3179e280a63ef1c64c143e60872 /repository_test.go | |
parent | a1f6ef44dfed1253ef7f3bc049f66b15f8fc2ab2 (diff) | |
download | go-git-6c2a0daafcd6c8f3f695c8b7a2c881d3abc276b1.tar.gz |
Ignore missing references on log --all
To mimic the actual standard git behavior, we must ignore references that are pointing to wrong/unexistent objects.
Signed-off-by: Antonio Jesus Navarro Perez <antnavper@gmail.com>
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go index 2a56dd2..1549737 100644 --- a/repository_test.go +++ b/repository_test.go @@ -1256,8 +1256,18 @@ func (s *RepositorySuite) TestLogAll(c *C) { err := r.clone(context.Background(), &CloneOptions{ URL: s.GetBasicLocalRepositoryURL(), }) + c.Assert(err, IsNil) + + rIter, err := r.Storer.IterReferences() + c.Assert(err, IsNil) + refCount := 0 + err = rIter.ForEach(func(ref *plumbing.Reference) error { + refCount++ + return nil + }) c.Assert(err, IsNil) + c.Assert(refCount, Equals, 5) cIter, err := r.Log(&LogOptions{ All: true, @@ -1286,6 +1296,58 @@ func (s *RepositorySuite) TestLogAll(c *C) { cIter.Close() } +func (s *RepositorySuite) TestLogAllMissingReferences(c *C) { + r, _ := Init(memory.NewStorage(), nil) + err := r.clone(context.Background(), &CloneOptions{ + URL: s.GetBasicLocalRepositoryURL(), + }) + c.Assert(err, IsNil) + err = r.Storer.RemoveReference(plumbing.HEAD) + c.Assert(err, IsNil) + + rIter, err := r.Storer.IterReferences() + c.Assert(err, IsNil) + + refCount := 0 + err = rIter.ForEach(func(ref *plumbing.Reference) error { + refCount++ + return nil + }) + c.Assert(err, IsNil) + c.Assert(refCount, Equals, 4) + + err = r.Storer.SetReference(plumbing.NewHashReference(plumbing.ReferenceName("DUMMY"), plumbing.NewHash("DUMMY"))) + c.Assert(err, IsNil) + + rIter, err = r.Storer.IterReferences() + c.Assert(err, IsNil) + + refCount = 0 + err = rIter.ForEach(func(ref *plumbing.Reference) error { + refCount++ + return nil + }) + c.Assert(err, IsNil) + c.Assert(refCount, Equals, 5) + + cIter, err := r.Log(&LogOptions{ + All: true, + }) + c.Assert(cIter, NotNil) + c.Assert(err, IsNil) + + cCount := 0 + cIter.ForEach(func(c *object.Commit) error { + cCount++ + return nil + }) + c.Assert(cCount, Equals, 9) + + _, err = cIter.Next() + c.Assert(err, Equals, io.EOF) + cIter.Close() +} + func (s *RepositorySuite) TestLogAllOrderByTime(c *C) { r, _ := Init(memory.NewStorage(), nil) err := r.clone(context.Background(), &CloneOptions{ |