aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-08 14:24:01 +0100
committerGitHub <noreply@github.com>2016-12-08 14:24:01 +0100
commita91727b6d5e6d8db17e960de6255bc848c78a076 (patch)
tree5c810b9a0c48f006318377cc0223179a28ce3642
parent45572a28635e63559dcc3b60c30c6ce09acb0a90 (diff)
downloadgo-git-a91727b6d5e6d8db17e960de6255bc848c78a076.tar.gz
repository: Ref -> Reference; Refs -> References. (#168)
-rw-r--r--examples/remotes/main.go2
-rw-r--r--repository.go15
-rw-r--r--repository_test.go40
3 files changed, 30 insertions, 27 deletions
diff --git a/examples/remotes/main.go b/examples/remotes/main.go
index 976c56d..43b127f 100644
--- a/examples/remotes/main.go
+++ b/examples/remotes/main.go
@@ -45,7 +45,7 @@ func main() {
// > git show-ref
color.Blue("git show-ref")
- refs, _ := r.Refs()
+ refs, _ := r.References()
refs.ForEach(func(ref *plumbing.Reference) error {
// The HEAD is omitted in a `git show-ref` so we ignore the symbolic
// references, the HEAD
diff --git a/repository.go b/repository.go
index 4486ff4..816cd09 100644
--- a/repository.go
+++ b/repository.go
@@ -224,7 +224,7 @@ func (r *Repository) createReferences(ref *plumbing.Reference) error {
// IsEmpty returns true if the repository is empty
func (r *Repository) IsEmpty() (bool, error) {
- iter, err := r.Refs()
+ iter, err := r.References()
if err != nil {
return false, err
}
@@ -395,13 +395,16 @@ func (r *Repository) Objects() (*ObjectIter, error) {
return NewObjectIter(r, iter), nil
}
-// Head returns the reference where HEAD is pointing
+// Head returns the reference where HEAD is pointing to.
func (r *Repository) Head() (*plumbing.Reference, error) {
return storer.ResolveReference(r.s, plumbing.HEAD)
}
-// Ref returns the Hash pointing the given refName
-func (r *Repository) Ref(name plumbing.ReferenceName, resolved bool) (*plumbing.Reference, error) {
+// Reference returns the reference for a given reference name. If resolved is
+// true, any symbolic reference will be resolved.
+func (r *Repository) Reference(name plumbing.ReferenceName, resolved bool) (
+ *plumbing.Reference, error) {
+
if resolved {
return storer.ResolveReference(r.s, name)
}
@@ -409,7 +412,7 @@ func (r *Repository) Ref(name plumbing.ReferenceName, resolved bool) (*plumbing.
return r.s.Reference(name)
}
-// Refs returns a map with all the References
-func (r *Repository) Refs() (storer.ReferenceIter, error) {
+// References returns a ReferenceIter for all references.
+func (r *Repository) References() (storer.ReferenceIter, error) {
return r.s.IterReferences()
}
diff --git a/repository_test.go b/repository_test.go
index 0b6a603..8ac3d9e 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -100,18 +100,18 @@ func (s *RepositorySuite) TestClone(c *C) {
c.Assert(err, IsNil)
c.Assert(remotes, HasLen, 1)
- head, err = r.Ref(plumbing.HEAD, false)
+ head, err = r.Reference(plumbing.HEAD, false)
c.Assert(err, IsNil)
c.Assert(head, NotNil)
c.Assert(head.Type(), Equals, plumbing.SymbolicReference)
c.Assert(head.Target().String(), Equals, "refs/heads/master")
- branch, err := r.Ref(head.Target(), false)
+ branch, err := r.Reference(head.Target(), false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- branch, err = r.Ref("refs/remotes/origin/master", false)
+ branch, err = r.Reference("refs/remotes/origin/master", false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Type(), Equals, plumbing.HashReference)
@@ -152,18 +152,18 @@ func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) {
c.Assert(err, IsNil)
c.Assert(remotes, HasLen, 1)
- head, err = r.Ref(plumbing.HEAD, false)
+ head, err = r.Reference(plumbing.HEAD, false)
c.Assert(err, IsNil)
c.Assert(head, NotNil)
c.Assert(head.Type(), Equals, plumbing.SymbolicReference)
c.Assert(head.Target().String(), Equals, "refs/heads/branch")
- branch, err := r.Ref(head.Target(), false)
+ branch, err := r.Reference(head.Target(), false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881")
- branch, err = r.Ref("refs/remotes/origin/branch", false)
+ branch, err = r.Reference("refs/remotes/origin/branch", false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Type(), Equals, plumbing.HashReference)
@@ -188,18 +188,18 @@ func (s *RepositorySuite) TestCloneSingleBranch(c *C) {
c.Assert(err, IsNil)
c.Assert(remotes, HasLen, 1)
- head, err = r.Ref(plumbing.HEAD, false)
+ head, err = r.Reference(plumbing.HEAD, false)
c.Assert(err, IsNil)
c.Assert(head, NotNil)
c.Assert(head.Type(), Equals, plumbing.SymbolicReference)
c.Assert(head.Target().String(), Equals, "refs/heads/master")
- branch, err := r.Ref(head.Target(), false)
+ branch, err := r.Reference(head.Target(), false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- branch, err = r.Ref("refs/remotes/origin/master", false)
+ branch, err = r.Reference("refs/remotes/origin/master", false)
c.Assert(err, IsNil)
c.Assert(branch, NotNil)
c.Assert(branch.Type(), Equals, plumbing.HashReference)
@@ -213,7 +213,7 @@ func (s *RepositorySuite) TestCloneDetachedHEAD(c *C) {
ReferenceName: plumbing.ReferenceName("refs/tags/v1.0.0"),
})
- head, err := r.Ref(plumbing.HEAD, false)
+ head, err := r.Reference(plumbing.HEAD, false)
c.Assert(err, IsNil)
c.Assert(head, NotNil)
c.Assert(head.Type(), Equals, plumbing.HashReference)
@@ -232,11 +232,11 @@ func (s *RepositorySuite) TestPullSingleBranch(c *C) {
err = r.Pull(&PullOptions{})
c.Assert(err, Equals, NoErrAlreadyUpToDate)
- branch, err := r.Ref("refs/heads/master", false)
+ branch, err := r.Reference("refs/heads/master", false)
c.Assert(err, IsNil)
c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- branch, err = r.Ref("refs/remotes/foo/branch", false)
+ branch, err = r.Reference("refs/remotes/foo/branch", false)
c.Assert(err, NotNil)
storage := r.s.(*memory.Storage)
@@ -256,11 +256,11 @@ func (s *RepositorySuite) TestPullA(c *C) {
storage := r.s.(*memory.Storage)
c.Assert(storage.Objects, HasLen, 31)
- branch, err := r.Ref("refs/heads/master", false)
+ branch, err := r.Reference("refs/heads/master", false)
c.Assert(err, IsNil)
c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
- branch, err = r.Ref("refs/remotes/origin/branch", false)
+ branch, err = r.Reference("refs/remotes/origin/branch", false)
c.Assert(err, IsNil)
c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881")
@@ -276,12 +276,12 @@ func (s *RepositorySuite) TestPullA(c *C) {
// the commit command has introduced a new commit, tree and blob
c.Assert(storage.Objects, HasLen, 34)
- branch, err = r.Ref("refs/heads/master", false)
+ branch, err = r.Reference("refs/heads/master", false)
c.Assert(err, IsNil)
c.Assert(branch.Hash().String(), Not(Equals), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
// the commit command, was in the local branch, so the remote should be read ok
- branch, err = r.Ref("refs/remotes/origin/branch", false)
+ branch, err = r.Reference("refs/remotes/origin/branch", false)
c.Assert(err, IsNil)
c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881")
}
@@ -387,7 +387,7 @@ func (s *RepositorySuite) TestTags(c *C) {
return nil
})
- refs, _ := r.Refs()
+ refs, _ := r.References()
refs.ForEach(func(ref *plumbing.Reference) error {
return nil
})
@@ -410,11 +410,11 @@ func (s *RepositorySuite) TestRef(c *C) {
err := r.Clone(&CloneOptions{URL: s.GetBasicLocalRepositoryURL()})
c.Assert(err, IsNil)
- ref, err := r.Ref(plumbing.HEAD, false)
+ ref, err := r.Reference(plumbing.HEAD, false)
c.Assert(err, IsNil)
c.Assert(ref.Name(), Equals, plumbing.HEAD)
- ref, err = r.Ref(plumbing.HEAD, true)
+ ref, err = r.Reference(plumbing.HEAD, true)
c.Assert(err, IsNil)
c.Assert(ref.Name(), Equals, plumbing.ReferenceName("refs/heads/master"))
}
@@ -426,7 +426,7 @@ func (s *RepositorySuite) TestRefs(c *C) {
c.Assert(err, IsNil)
- iter, err := r.Refs()
+ iter, err := r.References()
c.Assert(err, IsNil)
c.Assert(iter, NotNil)
}