aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-13 22:32:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-13 22:32:34 +0200
commit79087748f60f9aba219624a0fe9f4d33a0b51236 (patch)
tree1c0d17543ad742d1e97276796140f8b398b74802 /core
parenta65bcbc63bef24cf219c63d1b8cfb309c95d1c0f (diff)
downloadgo-git-79087748f60f9aba219624a0fe9f4d33a0b51236.tar.gz
Repository.Clone and Remote.Fetch tests and improvements
Diffstat (limited to 'core')
-rw-r--r--core/reference.go14
-rw-r--r--core/reference_test.go7
2 files changed, 21 insertions, 0 deletions
diff --git a/core/reference.go b/core/reference.go
index 4be4971..7d3f378 100644
--- a/core/reference.go
+++ b/core/reference.go
@@ -34,6 +34,20 @@ const (
// ReferenceName reference name's
type ReferenceName string
+// AsRemote returns a new remote reference name using current one as base
+func (r ReferenceName) AsRemote(remote string) ReferenceName {
+ return ReferenceName(refRemotePrefix + remote + "/" + r.alias())
+}
+
+func (r ReferenceName) String() string {
+ return string(r)
+}
+
+func (r ReferenceName) alias() string {
+ parts := strings.Split(string(r), "/")
+ return parts[len(parts)-1]
+}
+
const (
HEAD ReferenceName = "HEAD"
)
diff --git a/core/reference_test.go b/core/reference_test.go
index 05d20b4..5d88f0e 100644
--- a/core/reference_test.go
+++ b/core/reference_test.go
@@ -10,6 +10,13 @@ const (
ExampleReferenceName ReferenceName = "refs/heads/v4"
)
+func (s *ReferenceSuite) TestReferenceNameAsRemote(c *C) {
+ c.Assert(
+ ExampleReferenceName.AsRemote("foo").String(),
+ Equals, "refs/remotes/foo/v4",
+ )
+}
+
func (s *ReferenceSuite) TestNewReferenceFromStrings(c *C) {
r := NewReferenceFromStrings("refs/heads/v4", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
c.Assert(r.Type(), Equals, HashReference)