MCPcopy Create free account
hub / github.com/cli/cli / ParseRemoteTrackingRef

Function ParseRemoteTrackingRef

git/client.go:619–635  ·  view source on GitHub ↗

ParseRemoteTrackingRef parses a string of the form "refs/remotes/ / " into a RemoteTrackingBranch struct. If the string does not match this format, an error is returned. For now, we assume that refnames are of the format " / ", where the remote is a single path component

(s string)

Source from the content-addressed store, hash-verified

617//
618// When using this ref, git assumes it means `remote: foo` `branch: bar/baz`.
619func ParseRemoteTrackingRef(s string) (RemoteTrackingRef, error) {
620 prefix := "refs/remotes/"
621 if !strings.HasPrefix(s, prefix) {
622 return RemoteTrackingRef{}, fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: %s", s)
623 }
624
625 refName := strings.TrimPrefix(s, prefix)
626 refNameParts := strings.SplitN(refName, "/", 2)
627 if len(refNameParts) != 2 {
628 return RemoteTrackingRef{}, fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: %s", s)
629 }
630
631 return RemoteTrackingRef{
632 Remote: refNameParts[0],
633 Branch: refNameParts[1],
634 }, nil
635}
636
637// PushRevision gets the value of the @{push} revision syntax
638// An error here doesn't necessarily mean something is broken, but may mean that the @{push}

Callers 3

NewCreateContextFunction · 0.92
TestRemoteTrackingRefFunction · 0.85
PushRevisionMethod · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestRemoteTrackingRefFunction · 0.68