23 lines
584 B
Go
23 lines
584 B
Go
package git
|
|
|
|
import "strings"
|
|
|
|
// ParseAGitRef extracts target and source branch from an AGit push ref.
|
|
// AGit refs follow the pattern: refs/for/<target>[/<source>]
|
|
// Returns ("", "", false) if the ref is not an AGit ref.
|
|
func ParseAGitRef(ref string) (target, source string, ok bool) {
|
|
const prefix = "refs/for/"
|
|
if !strings.HasPrefix(ref, prefix) {
|
|
return "", "", false
|
|
}
|
|
rest := strings.TrimPrefix(ref, prefix)
|
|
parts := strings.SplitN(rest, "/", 2)
|
|
target = parts[0]
|
|
if len(parts) == 2 {
|
|
source = parts[1]
|
|
} else {
|
|
source = target
|
|
}
|
|
return target, source, true
|
|
}
|