25 lines
549 B
Go
25 lines
549 B
Go
package syw
|
|
|
|
import "strings"
|
|
|
|
// Ref is an object representing a commit in a repository.
|
|
type Ref struct {
|
|
Repo *Repository
|
|
Name string
|
|
Hash string
|
|
}
|
|
|
|
func (r Ref) IsBranch() bool { return strings.HasPrefix(r.Name, "refs/heads/") }
|
|
func (r Ref) IsTag() bool { return strings.HasPrefix(r.Name, "refs/tags/") }
|
|
|
|
// ShortName returns the branch or tag name with "refs/[heads|tags]/" trimmed off.
|
|
func (r Ref) ShortName() string {
|
|
if r.IsBranch() {
|
|
return r.Name[11:]
|
|
} else if r.IsTag() {
|
|
return r.Name[10:]
|
|
} else {
|
|
return r.Name
|
|
}
|
|
}
|