first round of files
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user