diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-08-02 13:42:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 13:42:19 +0200 |
commit | 902347aef9a7cd618c48e3baa1121b72e2beab68 (patch) | |
tree | b81859d6dfa3c580191a2ad60bc1b7d80a36991a /plumbing | |
parent | 9befb514d83e22268d00ab2c0fdd797b3742f0e9 (diff) | |
parent | ab655650034b2acf36ce0237acaaf28b5d2572c0 (diff) | |
download | go-git-902347aef9a7cd618c48e3baa1121b72e2beab68.tar.gz |
Merge pull request #531 from mcuadros/ref-name
plumbing: moved `Reference.Is*` methods to `ReferenceName.Is*`
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/reference.go | 40 | ||||
-rw-r--r-- | plumbing/reference_test.go | 8 |
2 files changed, 24 insertions, 24 deletions
diff --git a/plumbing/reference.go b/plumbing/reference.go index 5d477b9..2c30fe0 100644 --- a/plumbing/reference.go +++ b/plumbing/reference.go @@ -55,6 +55,26 @@ func (r ReferenceType) String() string { // ReferenceName reference name's type ReferenceName string +// IsBranch check if a reference is a branch +func (r ReferenceName) IsBranch() bool { + return strings.HasPrefix(string(r), refHeadPrefix) +} + +// IsNote check if a reference is a note +func (r ReferenceName) IsNote() bool { + return strings.HasPrefix(string(r), refNotePrefix) +} + +// IsRemote check if a reference is a remote +func (r ReferenceName) IsRemote() bool { + return strings.HasPrefix(string(r), refRemotePrefix) +} + +// IsTag check if a reference is a tag +func (r ReferenceName) IsTag() bool { + return strings.HasPrefix(string(r), refTagPrefix) +} + func (r ReferenceName) String() string { return string(r) } @@ -138,26 +158,6 @@ func (r *Reference) Target() ReferenceName { return r.target } -// IsBranch check if a reference is a branch -func (r *Reference) IsBranch() bool { - return strings.HasPrefix(string(r.n), refHeadPrefix) -} - -// IsNote check if a reference is a note -func (r *Reference) IsNote() bool { - return strings.HasPrefix(string(r.n), refNotePrefix) -} - -// IsRemote check if a reference is a remote -func (r *Reference) IsRemote() bool { - return strings.HasPrefix(string(r.n), refRemotePrefix) -} - -// IsTag check if a reference is a tag -func (r *Reference) IsTag() bool { - return strings.HasPrefix(string(r.n), refTagPrefix) -} - // Strings dump a reference as a [2]string func (r *Reference) Strings() [2]string { var o [2]string diff --git a/plumbing/reference_test.go b/plumbing/reference_test.go index 97c8772..47919ef 100644 --- a/plumbing/reference_test.go +++ b/plumbing/reference_test.go @@ -55,21 +55,21 @@ func (s *ReferenceSuite) TestNewHashReference(c *C) { } func (s *ReferenceSuite) TestIsBranch(c *C) { - r := NewHashReference(ExampleReferenceName, ZeroHash) + r := ExampleReferenceName c.Assert(r.IsBranch(), Equals, true) } func (s *ReferenceSuite) TestIsNote(c *C) { - r := NewHashReference(ReferenceName("refs/notes/foo"), ZeroHash) + r := ReferenceName("refs/notes/foo") c.Assert(r.IsNote(), Equals, true) } func (s *ReferenceSuite) TestIsRemote(c *C) { - r := NewHashReference(ReferenceName("refs/remotes/origin/master"), ZeroHash) + r := ReferenceName("refs/remotes/origin/master") c.Assert(r.IsRemote(), Equals, true) } func (s *ReferenceSuite) TestIsTag(c *C) { - r := NewHashReference(ReferenceName("refs/tags/v3.1."), ZeroHash) + r := ReferenceName("refs/tags/v3.1.") c.Assert(r.IsTag(), Equals, true) } |