MCPcopy
hub / github.com/cli/cli / ParseQualifiedHeadRef

Function ParseQualifiedHeadRef

pkg/cmd/pr/shared/find_refs_resolution.go:55–66  ·  view source on GitHub ↗

ParseQualifiedHeadRef takes strings of the form : or and returns a QualifiedHeadRef. If the form : is used, the owner is set to the value of , and the branch name is set to the value of . If the form is used, the owner is set to None, an

(ref string)

Source from the content-addressed store, hash-verified

53// it is not safe to assume the ref is truly a valid ref, e.g. "my~bad:ref?"
54// is going to result in a nonsense result.
55func ParseQualifiedHeadRef(ref string) (QualifiedHeadRef, error) {
56 if !strings.Contains(ref, ":") {
57 return NewQualifiedHeadRefWithoutOwner(ref), nil
58 }
59
60 parts := strings.Split(ref, ":")
61 if len(parts) != 2 {
62 return QualifiedHeadRef{}, fmt.Errorf("invalid qualified head ref format '%s'", ref)
63 }
64
65 return NewQualifiedHeadRef(parts[0], parts[1]), nil
66}
67
68// A QualifiedHeadRef without an owner returns <branch>, while a QualifiedHeadRef
69// with an owner returns <owner>:<branch>.

Callers 5

NewCreateContextFunction · 0.92
TestQualifiedHeadRefFunction · 0.85
FindMethod · 0.85

Calls 4

NewQualifiedHeadRefFunction · 0.85
ContainsMethod · 0.80
ErrorfMethod · 0.65

Tested by 3

TestQualifiedHeadRefFunction · 0.68