|
|
@ -6,6 +6,15 @@ package git |
|
|
|
|
|
|
|
|
|
|
|
import "strings" |
|
|
|
import "strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
// RemotePrefix is the base directory of the remotes information of git.
|
|
|
|
|
|
|
|
RemotePrefix = "refs/remotes/" |
|
|
|
|
|
|
|
// PullPrefix is the base directory of the pull information of git.
|
|
|
|
|
|
|
|
PullPrefix = "refs/pull/" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pullLen = len(PullPrefix) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Reference represents a Git ref.
|
|
|
|
// Reference represents a Git ref.
|
|
|
|
type Reference struct { |
|
|
|
type Reference struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
@ -24,17 +33,17 @@ func (ref *Reference) ShortName() string { |
|
|
|
if ref == nil { |
|
|
|
if ref == nil { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/heads/") { |
|
|
|
if strings.HasPrefix(ref.Name, BranchPrefix) { |
|
|
|
return ref.Name[11:] |
|
|
|
return strings.TrimPrefix(ref.Name, BranchPrefix) |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/tags/") { |
|
|
|
if strings.HasPrefix(ref.Name, TagPrefix) { |
|
|
|
return ref.Name[10:] |
|
|
|
return strings.TrimPrefix(ref.Name, TagPrefix) |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/remotes/") { |
|
|
|
if strings.HasPrefix(ref.Name, RemotePrefix) { |
|
|
|
return ref.Name[13:] |
|
|
|
return strings.TrimPrefix(ref.Name, RemotePrefix) |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 { |
|
|
|
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 { |
|
|
|
return ref.Name[10 : strings.IndexByte(ref.Name[10:], '/')+10] |
|
|
|
return ref.Name[pullLen : strings.IndexByte(ref.Name[pullLen:], '/')+pullLen] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ref.Name |
|
|
|
return ref.Name |
|
|
@ -45,16 +54,16 @@ func (ref *Reference) RefGroup() string { |
|
|
|
if ref == nil { |
|
|
|
if ref == nil { |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/heads/") { |
|
|
|
if strings.HasPrefix(ref.Name, BranchPrefix) { |
|
|
|
return "heads" |
|
|
|
return "heads" |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/tags/") { |
|
|
|
if strings.HasPrefix(ref.Name, TagPrefix) { |
|
|
|
return "tags" |
|
|
|
return "tags" |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/remotes/") { |
|
|
|
if strings.HasPrefix(ref.Name, RemotePrefix) { |
|
|
|
return "remotes" |
|
|
|
return "remotes" |
|
|
|
} |
|
|
|
} |
|
|
|
if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 { |
|
|
|
if strings.HasPrefix(ref.Name, PullPrefix) && strings.IndexByte(ref.Name[pullLen:], '/') > -1 { |
|
|
|
return "pull" |
|
|
|
return "pull" |
|
|
|
} |
|
|
|
} |
|
|
|
return "" |
|
|
|
return "" |
|
|
|