aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-03-21 10:27:56 +0100
committerGitHub <noreply@github.com>2017-03-21 10:27:56 +0100
commitf51d4a8476f865eef27011a9d90e03566c43d59c (patch)
tree70e500b28fb9025dffce4cdb106e2ca3c47d9c9e
parent5f4169fe242e7c80d779984a86a1de5a1eb78218 (diff)
parent0c82b411f6cdf4ec66689042d77c35efe41106c3 (diff)
downloadgo-git-f51d4a8476f865eef27011a9d90e03566c43d59c.tar.gz
Merge pull request #296 from ajnavarro/improvement/repository
git: Repository methods changes
-rw-r--r--_examples/clone/main.go2
-rw-r--r--_examples/log/main.go2
-rw-r--r--_examples/open/main.go2
-rw-r--r--_examples/showcase/main.go2
-rw-r--r--blame_test.go6
-rw-r--r--plumbing/storer/reference.go63
-rw-r--r--plumbing/storer/reference_test.go99
-rw-r--r--references_test.go6
-rw-r--r--repository.go93
-rw-r--r--repository_test.go192
-rw-r--r--worktree.go2
11 files changed, 426 insertions, 43 deletions
diff --git a/_examples/clone/main.go b/_examples/clone/main.go
index 3b24af2..1952e76 100644
--- a/_examples/clone/main.go
+++ b/_examples/clone/main.go
@@ -28,7 +28,7 @@ func main() {
ref, err := r.Head()
CheckIfError(err)
// ... retrieving the commit object
- commit, err := r.Commit(ref.Hash())
+ commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
fmt.Println(commit)
diff --git a/_examples/log/main.go b/_examples/log/main.go
index c77e5a5..e13df2c 100644
--- a/_examples/log/main.go
+++ b/_examples/log/main.go
@@ -30,7 +30,7 @@ func main() {
CheckIfError(err)
// ... retrieves the commit object
- commit, err := r.Commit(ref.Hash())
+ commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
// ... retrieves the commit history
diff --git a/_examples/open/main.go b/_examples/open/main.go
index a5364ed..0000f5e 100644
--- a/_examples/open/main.go
+++ b/_examples/open/main.go
@@ -25,7 +25,7 @@ func main() {
CheckIfError(err)
// ... retrieving the commit object
- commit, err := r.Commit(ref.Hash())
+ commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
// ... calculating the commit history
diff --git a/_examples/showcase/main.go b/_examples/showcase/main.go
index 7bd9d09..0170cd8 100644
--- a/_examples/showcase/main.go
+++ b/_examples/showcase/main.go
@@ -39,7 +39,7 @@ func main() {
CheckIfError(err)
// ... retrieving the commit object
- commit, err := r.Commit(ref.Hash())
+ commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
fmt.Println(commit)
diff --git a/blame_test.go b/blame_test.go
index be067e6..8bef4d0 100644
--- a/blame_test.go
+++ b/blame_test.go
@@ -26,7 +26,7 @@ func (s *BlameSuite) TestBlame(c *C) {
r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One())
exp := s.mockBlame(c, t, r)
- commit, err := r.Commit(plumbing.NewHash(t.rev))
+ commit, err := r.CommitObject(plumbing.NewHash(t.rev))
c.Assert(err, IsNil)
obt, err := Blame(commit, t.path)
@@ -36,7 +36,7 @@ func (s *BlameSuite) TestBlame(c *C) {
}
func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameResult) {
- commit, err := r.Commit(plumbing.NewHash(t.rev))
+ commit, err := r.CommitObject(plumbing.NewHash(t.rev))
c.Assert(err, IsNil, Commentf("%v: repo=%s, rev=%s", err, t.repo, t.rev))
f, err := commit.File(t.path)
@@ -48,7 +48,7 @@ func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameRe
blamedLines := make([]*Line, 0, len(t.blames))
for i := range t.blames {
- commit, err := r.Commit(plumbing.NewHash(t.blames[i]))
+ commit, err := r.CommitObject(plumbing.NewHash(t.blames[i]))
c.Assert(err, IsNil)
l := &Line{
Author: commit.Author.Email,
diff --git a/plumbing/storer/reference.go b/plumbing/storer/reference.go
index bc063b6..988c784 100644
--- a/plumbing/storer/reference.go
+++ b/plumbing/storer/reference.go
@@ -28,6 +28,67 @@ type ReferenceIter interface {
Close()
}
+type referenceFilteredIter struct {
+ ff func(r *plumbing.Reference) bool
+ iter ReferenceIter
+}
+
+// NewReferenceFilteredIter returns a reference iterator for the given reference
+// Iterator. This iterator will iterate only references that accomplish the
+// provided function.
+func NewReferenceFilteredIter(
+ ff func(r *plumbing.Reference) bool, iter ReferenceIter) ReferenceIter {
+ return &referenceFilteredIter{ff, iter}
+}
+
+// Next returns the next reference from the iterator. If the iterator has reached
+// the end it will return io.EOF as an error.
+func (iter *referenceFilteredIter) Next() (*plumbing.Reference, error) {
+ for {
+ r, err := iter.iter.Next()
+ if err != nil {
+ return nil, err
+ }
+
+ if iter.ff(r) {
+ return r, nil
+ }
+
+ continue
+ }
+}
+
+// ForEach call the cb function for each reference contained on this iter until
+// an error happens or the end of the iter is reached. If ErrStop is sent
+// the iteration is stopped but no error is returned. The iterator is closed.
+func (iter *referenceFilteredIter) ForEach(cb func(*plumbing.Reference) error) error {
+ defer iter.Close()
+ for {
+ r, err := iter.Next()
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ return err
+ }
+
+ if err := cb(r); err != nil {
+ if err == ErrStop {
+ break
+ }
+
+ return err
+ }
+ }
+
+ return nil
+}
+
+// Close releases any resources used by the iterator.
+func (iter *referenceFilteredIter) Close() {
+ iter.iter.Close()
+}
+
// ReferenceSliceIter implements ReferenceIter. It iterates over a series of
// references stored in a slice and yields each one in turn when Next() is
// called.
@@ -41,7 +102,7 @@ type ReferenceSliceIter struct {
// NewReferenceSliceIter returns a reference iterator for the given slice of
// objects.
-func NewReferenceSliceIter(series []*plumbing.Reference) *ReferenceSliceIter {
+func NewReferenceSliceIter(series []*plumbing.Reference) ReferenceIter {
return &ReferenceSliceIter{
series: series,
}
diff --git a/plumbing/storer/reference_test.go b/plumbing/storer/reference_test.go
index ee6c95d..5738eef 100644
--- a/plumbing/storer/reference_test.go
+++ b/plumbing/storer/reference_test.go
@@ -89,3 +89,102 @@ func (s *ReferenceSuite) TestReferenceSliceIterForEachStop(c *C) {
c.Assert(count, Equals, 1)
}
+
+func (s *ReferenceSuite) TestReferenceFilteredIterNext(c *C) {
+ slice := []*plumbing.Reference{
+ plumbing.NewReferenceFromStrings("foo", "foo"),
+ plumbing.NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool {
+ if r.Name() == "bar" {
+ return true
+ }
+
+ return false
+ }, NewReferenceSliceIter(slice))
+ foo, err := i.Next()
+ c.Assert(err, IsNil)
+ c.Assert(foo == slice[0], Equals, false)
+ c.Assert(foo == slice[1], Equals, true)
+
+ empty, err := i.Next()
+ c.Assert(err, Equals, io.EOF)
+ c.Assert(empty, IsNil)
+}
+
+func (s *ReferenceSuite) TestReferenceFilteredIterForEach(c *C) {
+ slice := []*plumbing.Reference{
+ plumbing.NewReferenceFromStrings("foo", "foo"),
+ plumbing.NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool {
+ if r.Name() == "bar" {
+ return true
+ }
+
+ return false
+ }, NewReferenceSliceIter(slice))
+ var count int
+ i.ForEach(func(r *plumbing.Reference) error {
+ c.Assert(r == slice[1], Equals, true)
+ count++
+ return nil
+ })
+
+ c.Assert(count, Equals, 1)
+}
+
+func (s *ReferenceSuite) TestReferenceFilteredIterError(c *C) {
+ slice := []*plumbing.Reference{
+ plumbing.NewReferenceFromStrings("foo", "foo"),
+ plumbing.NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool {
+ if r.Name() == "bar" {
+ return true
+ }
+
+ return false
+ }, NewReferenceSliceIter(slice))
+ var count int
+ exampleErr := errors.New("SOME ERROR")
+ err := i.ForEach(func(r *plumbing.Reference) error {
+ c.Assert(r == slice[1], Equals, true)
+ count++
+ if count == 1 {
+ return exampleErr
+ }
+
+ return nil
+ })
+
+ c.Assert(err, Equals, exampleErr)
+ c.Assert(count, Equals, 1)
+}
+
+func (s *ReferenceSuite) TestReferenceFilteredIterForEachStop(c *C) {
+ slice := []*plumbing.Reference{
+ plumbing.NewReferenceFromStrings("foo", "foo"),
+ plumbing.NewReferenceFromStrings("bar", "bar"),
+ }
+
+ i := NewReferenceFilteredIter(func(r *plumbing.Reference) bool {
+ if r.Name() == "bar" {
+ return true
+ }
+
+ return false
+ }, NewReferenceSliceIter(slice))
+
+ var count int
+ i.ForEach(func(r *plumbing.Reference) error {
+ c.Assert(r == slice[1], Equals, true)
+ count++
+ return ErrStop
+ })
+
+ c.Assert(count, Equals, 1)
+}
diff --git a/references_test.go b/references_test.go
index af59c05..e901ec0 100644
--- a/references_test.go
+++ b/references_test.go
@@ -291,7 +291,7 @@ func (s *ReferencesSuite) TestRevList(c *C) {
for _, t := range referencesTests {
r := s.NewRepositoryFromPackfile(fixtures.ByURL(t.repo).One())
- commit, err := r.Commit(plumbing.NewHash(t.commit))
+ commit, err := r.CommitObject(plumbing.NewHash(t.commit))
c.Assert(err, IsNil)
revs, err := References(commit, t.path)
@@ -300,7 +300,7 @@ func (s *ReferencesSuite) TestRevList(c *C) {
for i := range revs {
if revs[i].Hash.String() != t.revs[i] {
- commit, err := s.Repository.Commit(plumbing.NewHash(t.revs[i]))
+ commit, err := s.Repository.CommitObject(plumbing.NewHash(t.revs[i]))
c.Assert(err, IsNil)
equiv, err := equivalent(t.path, revs[i], commit)
c.Assert(err, IsNil)
@@ -358,7 +358,7 @@ func (s *ReferencesSuite) commits(c *C, repo string, hs ...string) []*object.Com
result := make([]*object.Commit, 0, len(hs))
for _, h := range hs {
- commit, err := r.Commit(plumbing.NewHash(h))
+ commit, err := r.CommitObject(plumbing.NewHash(h))
c.Assert(err, IsNil)
result = append(result, commit)
diff --git a/repository.go b/repository.go
index ffb61d8..9e325e4 100644
--- a/repository.go
+++ b/repository.go
@@ -608,30 +608,54 @@ func (r *Repository) Push(o *PushOptions) error {
return remote.Push(o)
}
-// Commit return a Commit with the given hash. If not found
-// plumbing.ErrObjectNotFound is returned
-func (r *Repository) Commit(h plumbing.Hash) (*object.Commit, error) {
- return object.GetCommit(r.Storer, h)
+// Tags returns all the References from Tags. This method returns all the tag
+// types, lightweight, and annotated ones.
+func (r *Repository) Tags() (storer.ReferenceIter, error) {
+ refIter, err := r.Storer.IterReferences()
+ if err != nil {
+ return nil, err
+ }
+
+ return storer.NewReferenceFilteredIter(
+ func(r *plumbing.Reference) bool {
+ return r.IsTag()
+ }, refIter), nil
}
-// Commits returns an unsorted CommitIter with all the commits in the repository
-func (r *Repository) Commits() (*object.CommitIter, error) {
- iter, err := r.Storer.IterEncodedObjects(plumbing.CommitObject)
+// Branches returns all the References that are Branches.
+func (r *Repository) Branches() (storer.ReferenceIter, error) {
+ refIter, err := r.Storer.IterReferences()
if err != nil {
return nil, err
}
- return object.NewCommitIter(r.Storer, iter), nil
+ return storer.NewReferenceFilteredIter(
+ func(r *plumbing.Reference) bool {
+ return r.IsBranch()
+ }, refIter), nil
+}
+
+// Notes returns all the References that are Branches.
+func (r *Repository) Notes() (storer.ReferenceIter, error) {
+ refIter, err := r.Storer.IterReferences()
+ if err != nil {
+ return nil, err
+ }
+
+ return storer.NewReferenceFilteredIter(
+ func(r *plumbing.Reference) bool {
+ return r.IsNote()
+ }, refIter), nil
}
-// Tree return a Tree with the given hash. If not found
+// TreeObject return a Tree with the given hash. If not found
// plumbing.ErrObjectNotFound is returned
-func (r *Repository) Tree(h plumbing.Hash) (*object.Tree, error) {
+func (r *Repository) TreeObject(h plumbing.Hash) (*object.Tree, error) {
return object.GetTree(r.Storer, h)
}
-// Trees returns an unsorted TreeIter with all the trees in the repository
-func (r *Repository) Trees() (*object.TreeIter, error) {
+// TreeObjects returns an unsorted TreeIter with all the trees in the repository
+func (r *Repository) TreeObjects() (*object.TreeIter, error) {
iter, err := r.Storer.IterEncodedObjects(plumbing.TreeObject)
if err != nil {
return nil, err
@@ -640,14 +664,30 @@ func (r *Repository) Trees() (*object.TreeIter, error) {
return object.NewTreeIter(r.Storer, iter), nil
}
-// Blob returns a Blob with the given hash. If not found
-// plumbing.ErrObjectNotFound is returne
-func (r *Repository) Blob(h plumbing.Hash) (*object.Blob, error) {
+// CommitObject return a Commit with the given hash. If not found
+// plumbing.ErrObjectNotFound is returned.
+func (r *Repository) CommitObject(h plumbing.Hash) (*object.Commit, error) {
+ return object.GetCommit(r.Storer, h)
+}
+
+// CommitObjects returns an unsorted CommitIter with all the commits in the repository.
+func (r *Repository) CommitObjects() (*object.CommitIter, error) {
+ iter, err := r.Storer.IterEncodedObjects(plumbing.CommitObject)
+ if err != nil {
+ return nil, err
+ }
+
+ return object.NewCommitIter(r.Storer, iter), nil
+}
+
+// BlobObject returns a Blob with the given hash. If not found
+// plumbing.ErrObjectNotFound is returned.
+func (r *Repository) BlobObject(h plumbing.Hash) (*object.Blob, error) {
return object.GetBlob(r.Storer, h)
}
-// Blobs returns an unsorted BlobIter with all the blobs in the repository
-func (r *Repository) Blobs() (*object.BlobIter, error) {
+// BlobObjects returns an unsorted BlobIter with all the blobs in the repository.
+func (r *Repository) BlobObjects() (*object.BlobIter, error) {
iter, err := r.Storer.IterEncodedObjects(plumbing.BlobObject)
if err != nil {
return nil, err
@@ -656,15 +696,16 @@ func (r *Repository) Blobs() (*object.BlobIter, error) {
return object.NewBlobIter(r.Storer, iter), nil
}
-// Tag returns a Tag with the given hash. If not found
-// plumbing.ErrObjectNotFound is returned
-func (r *Repository) Tag(h plumbing.Hash) (*object.Tag, error) {
+// TagObject returns a Tag with the given hash. If not found
+// plumbing.ErrObjectNotFound is returned. This method only returns
+// annotated Tags, no lightweight Tags.
+func (r *Repository) TagObject(h plumbing.Hash) (*object.Tag, error) {
return object.GetTag(r.Storer, h)
}
-// Tags returns a unsorted TagIter that can step through all of the annotated
+// TagObjects returns a unsorted TagIter that can step through all of the annotated
// tags in the repository.
-func (r *Repository) Tags() (*object.TagIter, error) {
+func (r *Repository) TagObjects() (*object.TagIter, error) {
iter, err := r.Storer.IterEncodedObjects(plumbing.TagObject)
if err != nil {
return nil, err
@@ -674,7 +715,7 @@ func (r *Repository) Tags() (*object.TagIter, error) {
}
// Object returns an Object with the given hash. If not found
-// plumbing.ErrObjectNotFound is returned
+// plumbing.ErrObjectNotFound is returned.
func (r *Repository) Object(t plumbing.ObjectType, h plumbing.Hash) (object.Object, error) {
obj, err := r.Storer.EncodedObject(t, h)
if err != nil {
@@ -688,7 +729,7 @@ func (r *Repository) Object(t plumbing.ObjectType, h plumbing.Hash) (object.Obje
return object.DecodeObject(r.Storer, obj)
}
-// Objects returns an unsorted BlobIter with all the objects in the repository
+// Objects returns an unsorted ObjectIter with all the objects in the repository.
func (r *Repository) Objects() (*object.ObjectIter, error) {
iter, err := r.Storer.IterEncodedObjects(plumbing.AnyObject)
if err != nil {
@@ -730,7 +771,7 @@ func (r *Repository) Worktree() (*Worktree, error) {
return &Worktree{r: r, fs: r.wt}, nil
}
-// ResolveRevision resolves revision to corresponding hash
+// ResolveRevision resolves revision to corresponding hash.
func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error) {
p := revision.NewParserFromString(string(rev))
@@ -753,7 +794,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
h := ref.Hash()
- commit, err = r.Commit(h)
+ commit, err = r.CommitObject(h)
if err != nil {
return &plumbing.ZeroHash, err
diff --git a/repository_test.go b/repository_test.go
index 2503278..352ff21 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -697,7 +697,7 @@ func (s *RepositorySuite) TestCommit(c *C) {
c.Assert(err, IsNil)
hash := plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47")
- commit, err := r.Commit(hash)
+ commit, err := r.CommitObject(hash)
c.Assert(err, IsNil)
c.Assert(commit.Hash.IsZero(), Equals, false)
@@ -718,7 +718,7 @@ func (s *RepositorySuite) TestCommits(c *C) {
c.Assert(err, IsNil)
count := 0
- commits, err := r.Commits()
+ commits, err := r.CommitObjects()
c.Assert(err, IsNil)
for {
commit, err := commits.Next()
@@ -735,7 +735,52 @@ func (s *RepositorySuite) TestCommits(c *C) {
c.Assert(count, Equals, 9)
}
-func (s *RepositorySuite) TestTag(c *C) {
+func (s *RepositorySuite) TestBlob(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{
+ URL: s.GetBasicLocalRepositoryURL(),
+ })
+
+ c.Assert(err, IsNil)
+
+ blob, err := r.BlobObject(plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"))
+ c.Assert(err, NotNil)
+ c.Assert(blob, IsNil)
+
+ blobHash := plumbing.NewHash("9a48f23120e880dfbe41f7c9b7b708e9ee62a492")
+ blob, err = r.BlobObject(blobHash)
+ c.Assert(err, IsNil)
+
+ c.Assert(blob.Hash.IsZero(), Equals, false)
+ c.Assert(blob.Hash, Equals, blob.ID())
+ c.Assert(blob.Hash, Equals, blobHash)
+ c.Assert(blob.Type(), Equals, plumbing.BlobObject)
+}
+
+func (s *RepositorySuite) TestBlobs(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
+ c.Assert(err, IsNil)
+
+ count := 0
+ blobs, err := r.BlobObjects()
+ c.Assert(err, IsNil)
+ for {
+ blob, err := blobs.Next()
+ if err != nil {
+ break
+ }
+
+ count++
+ c.Assert(blob.Hash.IsZero(), Equals, false)
+ c.Assert(blob.Hash, Equals, blob.ID())
+ c.Assert(blob.Type(), Equals, plumbing.BlobObject)
+ }
+
+ c.Assert(count, Equals, 10)
+}
+
+func (s *RepositorySuite) TestTagObject(c *C) {
url := s.GetLocalRepositoryURL(
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
)
@@ -745,7 +790,7 @@ func (s *RepositorySuite) TestTag(c *C) {
c.Assert(err, IsNil)
hash := plumbing.NewHash("ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")
- tag, err := r.Tag(hash)
+ tag, err := r.TagObject(hash)
c.Assert(err, IsNil)
c.Assert(tag.Hash.IsZero(), Equals, false)
@@ -766,6 +811,121 @@ func (s *RepositorySuite) TestTags(c *C) {
tags, err := r.Tags()
c.Assert(err, IsNil)
+ tags.ForEach(func(tag *plumbing.Reference) error {
+ count++
+ c.Assert(tag.Hash().IsZero(), Equals, false)
+ c.Assert(tag.IsTag(), Equals, true)
+ return nil
+ })
+
+ c.Assert(count, Equals, 5)
+}
+
+func (s *RepositorySuite) TestBranches(c *C) {
+ f := fixtures.ByURL("https://github.com/git-fixtures/root-references.git").One()
+ sto, err := filesystem.NewStorage(f.DotGit())
+ c.Assert(err, IsNil)
+ r, err := Open(sto, f.DotGit())
+ c.Assert(err, IsNil)
+
+ count := 0
+ branches, err := r.Branches()
+ c.Assert(err, IsNil)
+
+ branches.ForEach(func(branch *plumbing.Reference) error {
+ count++
+ c.Assert(branch.Hash().IsZero(), Equals, false)
+ c.Assert(branch.IsBranch(), Equals, true)
+ return nil
+ })
+
+ c.Assert(count, Equals, 8)
+}
+
+func (s *RepositorySuite) TestNotes(c *C) {
+ // TODO add fixture with Notes
+ url := s.GetLocalRepositoryURL(
+ fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
+ )
+
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{URL: url})
+ c.Assert(err, IsNil)
+
+ count := 0
+ notes, err := r.Notes()
+ c.Assert(err, IsNil)
+
+ notes.ForEach(func(note *plumbing.Reference) error {
+ count++
+ c.Assert(note.Hash().IsZero(), Equals, false)
+ c.Assert(note.IsNote(), Equals, true)
+ return nil
+ })
+
+ c.Assert(count, Equals, 0)
+}
+
+func (s *RepositorySuite) TestTree(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{
+ URL: s.GetBasicLocalRepositoryURL(),
+ })
+ c.Assert(err, IsNil)
+
+ invalidHash := plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
+ tree, err := r.TreeObject(invalidHash)
+ c.Assert(tree, IsNil)
+ c.Assert(err, NotNil)
+
+ hash := plumbing.NewHash("dbd3641b371024f44d0e469a9c8f5457b0660de1")
+ tree, err = r.TreeObject(hash)
+ c.Assert(err, IsNil)
+
+ c.Assert(tree.Hash.IsZero(), Equals, false)
+ c.Assert(tree.Hash, Equals, tree.ID())
+ c.Assert(tree.Hash, Equals, hash)
+ c.Assert(tree.Type(), Equals, plumbing.TreeObject)
+ c.Assert(len(tree.Entries), Not(Equals), 0)
+}
+
+func (s *RepositorySuite) TestTrees(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
+ c.Assert(err, IsNil)
+
+ count := 0
+ trees, err := r.TreeObjects()
+ c.Assert(err, IsNil)
+ for {
+ tree, err := trees.Next()
+ if err != nil {
+ break
+ }
+
+ count++
+ c.Assert(tree.Hash.IsZero(), Equals, false)
+ c.Assert(tree.Hash, Equals, tree.ID())
+ c.Assert(tree.Type(), Equals, plumbing.TreeObject)
+ c.Assert(len(tree.Entries), Not(Equals), 0)
+ }
+
+ c.Assert(count, Equals, 12)
+}
+
+func (s *RepositorySuite) TestTagObjects(c *C) {
+ url := s.GetLocalRepositoryURL(
+ fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
+ )
+
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{URL: url})
+ c.Assert(err, IsNil)
+
+ count := 0
+ tags, err := r.TagObjects()
+ c.Assert(err, IsNil)
+
tags.ForEach(func(tag *object.Tag) error {
count++
@@ -787,7 +947,7 @@ func (s *RepositorySuite) TestCommitIterClosePanic(c *C) {
err := r.clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
c.Assert(err, IsNil)
- commits, err := r.Commits()
+ commits, err := r.CommitObjects()
c.Assert(err, IsNil)
commits.Close()
}
@@ -831,6 +991,28 @@ func (s *RepositorySuite) TestObject(c *C) {
c.Assert(o.Type(), Equals, plumbing.CommitObject)
}
+func (s *RepositorySuite) TestObjects(c *C) {
+ r, _ := Init(memory.NewStorage(), nil)
+ err := r.clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
+ c.Assert(err, IsNil)
+
+ count := 0
+ objects, err := r.Objects()
+ c.Assert(err, IsNil)
+ for {
+ o, err := objects.Next()
+ if err != nil {
+ break
+ }
+
+ count++
+ c.Assert(o.ID().IsZero(), Equals, false)
+ c.Assert(o.Type(), Not(Equals), plumbing.AnyObject)
+ }
+
+ c.Assert(count, Equals, 31)
+}
+
func (s *RepositorySuite) TestObjectNotFound(c *C) {
r, _ := Init(memory.NewStorage(), nil)
err := r.clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
diff --git a/worktree.go b/worktree.go
index 5ef2fe9..40ebe58 100644
--- a/worktree.go
+++ b/worktree.go
@@ -34,7 +34,7 @@ func (w *Worktree) Checkout(commit plumbing.Hash) error {
return ErrWorktreeNotClean
}
- c, err := w.r.Commit(commit)
+ c, err := w.r.CommitObject(commit)
if err != nil {
return err
}