@@ -55,40 +55,57 @@ func (ref *Reference) Commit() (*Commit, error) {
5555
5656// ShortName returns the short name of the reference
5757func (ref * Reference ) ShortName () string {
58- if ref == nil {
59- return ""
60- }
61- if strings .HasPrefix (ref .Name , BranchPrefix ) {
62- return strings .TrimPrefix (ref .Name , BranchPrefix )
58+ return RefName (ref .Name ).ShortName ()
59+ }
60+
61+ // RefGroup returns the group type of the reference
62+ func (ref * Reference ) RefGroup () string {
63+ return RefName (ref .Name ).RefGroup ()
64+ }
65+
66+ // RefName represents a git reference name
67+ type RefName string
68+
69+ func (ref RefName ) IsBranch () bool {
70+ return strings .HasPrefix (string (ref ), BranchPrefix )
71+ }
72+
73+ func (ref RefName ) IsTag () bool {
74+ return strings .HasPrefix (string (ref ), TagPrefix )
75+ }
76+
77+ // ShortName returns the short name of the reference name
78+ func (ref RefName ) ShortName () string {
79+ refName := string (ref )
80+ if strings .HasPrefix (refName , BranchPrefix ) {
81+ return strings .TrimPrefix (refName , BranchPrefix )
6382 }
64- if strings .HasPrefix (ref . Name , TagPrefix ) {
65- return strings .TrimPrefix (ref . Name , TagPrefix )
83+ if strings .HasPrefix (refName , TagPrefix ) {
84+ return strings .TrimPrefix (refName , TagPrefix )
6685 }
67- if strings .HasPrefix (ref . Name , RemotePrefix ) {
68- return strings .TrimPrefix (ref . Name , RemotePrefix )
86+ if strings .HasPrefix (refName , RemotePrefix ) {
87+ return strings .TrimPrefix (refName , RemotePrefix )
6988 }
70- if strings .HasPrefix (ref . Name , PullPrefix ) && strings .IndexByte (ref . Name [pullLen :], '/' ) > - 1 {
71- return ref . Name [pullLen : strings .IndexByte (ref . Name [pullLen :], '/' )+ pullLen ]
89+ if strings .HasPrefix (refName , PullPrefix ) && strings .IndexByte (refName [pullLen :], '/' ) > - 1 {
90+ return refName [pullLen : strings .IndexByte (refName [pullLen :], '/' )+ pullLen ]
7291 }
7392
74- return ref . Name
93+ return refName
7594}
7695
7796// RefGroup returns the group type of the reference
78- func (ref * Reference ) RefGroup () string {
79- if ref == nil {
80- return ""
81- }
82- if strings .HasPrefix (ref .Name , BranchPrefix ) {
97+ func (ref RefName ) RefGroup () string {
98+ refName := string (ref )
99+ if strings .HasPrefix (refName , BranchPrefix ) {
83100 return "heads"
84101 }
85- if strings .HasPrefix (ref . Name , TagPrefix ) {
102+ if strings .HasPrefix (refName , TagPrefix ) {
86103 return "tags"
87104 }
88- if strings .HasPrefix (ref . Name , RemotePrefix ) {
105+ if strings .HasPrefix (refName , RemotePrefix ) {
89106 return "remotes"
90107 }
91- if strings .HasPrefix (ref . Name , PullPrefix ) && strings .IndexByte (ref . Name [pullLen :], '/' ) > - 1 {
108+ if strings .HasPrefix (refName , PullPrefix ) && strings .IndexByte (refName [pullLen :], '/' ) > - 1 {
92109 return "pull"
93110 }
94111 return ""
0 commit comments