1package git
2
3import (
4 "strings"
5
6 git "github.com/aymanbagabas/git-module"
7)
8
9const (
10 // HEAD represents the name of the HEAD reference.
11 HEAD = "HEAD"
12 // RefsHeads represents the prefix for branch references.
13 RefsHeads = git.RefsHeads
14 // RefsTags represents the prefix for tag references.
15 RefsTags = git.RefsTags
16)
17
18// Reference is a wrapper around git.Reference with helper methods.
19type Reference struct {
20 *git.Reference
21 path string // repo path
22}
23
24// ReferenceName is a Refspec wrapper.
25type ReferenceName string
26
27// String returns the reference name i.e. refs/heads/master.
28func (r ReferenceName) String() string {
29 return string(r)
30}
31
32// Short returns the short name of the reference i.e. master.
33func (r ReferenceName) Short() string {
34 return git.RefShortName(string(r))
35}
36
37// Name returns the reference name i.e. refs/heads/master.
38func (r *Reference) Name() ReferenceName {
39 return ReferenceName(r.Refspec)
40}
41
42// IsBranch returns true if the reference is a branch.
43func (r *Reference) IsBranch() bool {
44 return strings.HasPrefix(r.Refspec, git.RefsHeads)
45}
46
47// IsTag returns true if the reference is a tag.
48func (r *Reference) IsTag() bool {
49 return strings.HasPrefix(r.Refspec, git.RefsTags)
50}