MCPcopy
hub / github.com/cli/cli / ParseURL

Function ParseURL

git/url.go:29–61  ·  view source on GitHub ↗

ParseURL normalizes git remote urls

(rawURL string)

Source from the content-addressed store, hash-verified

27
28// ParseURL normalizes git remote urls
29func ParseURL(rawURL string) (*url.URL, error) {
30 if !isPossibleProtocol(rawURL) &&
31 strings.ContainsRune(rawURL, ':') &&
32 // not a Windows path
33 !strings.ContainsRune(rawURL, '\\') {
34 // support scp-like syntax for ssh protocol
35 rawURL = "ssh://" + strings.Replace(rawURL, ":", "/", 1)
36 }
37
38 u, err := url.Parse(rawURL)
39 if err != nil {
40 return nil, err
41 }
42
43 switch u.Scheme {
44 case "git+https":
45 u.Scheme = "https"
46 case "git+ssh":
47 u.Scheme = "ssh"
48 }
49
50 if u.Scheme != "ssh" {
51 return u, nil
52 }
53
54 if strings.HasPrefix(u.Path, "//") {
55 u.Path = strings.TrimPrefix(u.Path, "/")
56 }
57
58 u.Host = strings.TrimSuffix(u.Host, ":"+u.Port())
59
60 return u, nil
61}

Callers 12

cloneRunFunction · 0.92
forkRunFunction · 0.92
parseGitHubURLFunction · 0.92
OwnerMethod · 0.92
NewCmdExtensionFunction · 0.92
getExtensionsFunction · 0.92
RepoNameFromRemoteFunction · 0.92
TestParseURLFunction · 0.70
AddRemoteMethod · 0.70
parseRemotesFunction · 0.70
parseRemoteURLOrNameFunction · 0.70

Calls 2

isPossibleProtocolFunction · 0.85
ReplaceMethod · 0.80

Tested by 1

TestParseURLFunction · 0.56