diff options
author | Yusuke Hatanaka <arbalestimp@gmail.com> | 2017-03-28 12:47:24 +0900 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-03-28 05:47:24 +0200 |
commit | e190c37cf51a2a320cabd81b25057859ed689a3b (patch) | |
tree | 9620c6636b29c008194c75230d1b119e38db4dad /plumbing/reference.go | |
parent | 62ad629b9a4213fdb8d33bcc7e0bea66d043fc41 (diff) | |
download | go-git-e190c37cf51a2a320cabd81b25057859ed689a3b.tar.gz |
plumbing: Reference, support slash separated branch (#302)
Diffstat (limited to 'plumbing/reference.go')
-rw-r--r-- | plumbing/reference.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/plumbing/reference.go b/plumbing/reference.go index 798c3dd..8fa103e 100644 --- a/plumbing/reference.go +++ b/plumbing/reference.go @@ -16,6 +16,16 @@ const ( ) var ( + refPrefixes = []string{ + refHeadPrefix, + refTagPrefix, + refRemotePrefix, + refNotePrefix, + refPrefix, + } +) + +var ( ErrReferenceNotFound = errors.New("reference not found") ) @@ -50,8 +60,17 @@ func (r ReferenceName) String() string { // Short returns the short name of a ReferenceName func (r ReferenceName) Short() string { - parts := strings.Split(string(r), "/") - return parts[len(parts)-1] + return r.removeRefPrefix() +} + +// Instead of hardcoding a number of components, we should remove the prefixes +// refHeadPrefix, refTagPrefix, refRemotePrefix, refNotePrefix and refPrefix +func (r ReferenceName) removeRefPrefix() string { + s := string(r) + for _, prefix := range refPrefixes { + s = strings.TrimPrefix(s, prefix) + } + return s } const ( |