ParseURL parses a BuildKit-style Git URL (that may contain additional fragment metadata) and returns a parsed GitURL object.
(remote string)
| 114 | // ParseURL parses a BuildKit-style Git URL (that may contain additional |
| 115 | // fragment metadata) and returns a parsed GitURL object. |
| 116 | func ParseURL(remote string) (*GitURL, error) { |
| 117 | if proto := protoRegexp.FindString(remote); proto != "" { |
| 118 | proto = strings.ToLower(strings.TrimSuffix(proto, "://")) |
| 119 | if _, ok := supportedProtos[proto]; !ok { |
| 120 | return nil, fmt.Errorf("%w %q", ErrInvalidProtocol, proto) |
| 121 | } |
| 122 | url, err := url.Parse(remote) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | return fromURL(url), nil |
| 127 | } |
| 128 | |
| 129 | if url, err := sshutil.ParseSCPStyleURL(remote); err == nil { |
| 130 | return fromSCPStyleURL(url), nil |
| 131 | } |
| 132 | |
| 133 | return nil, ErrUnknownProtocol |
| 134 | } |
| 135 | |
| 136 | // cloneURLFallbackProtocols is the priority order for resolving a clone ref |
| 137 | // that omits its scheme (e.g. "github.com/foo/bar"). Callers iterate the |