MCPcopy
hub / github.com/git-lfs/git-lfs / ValidateRemoteURL

Function ValidateRemoteURL

git/git.go:595–616  ·  view source on GitHub ↗

ValidateRemoteURL checks that a string is a valid Git remote URL

(remote string)

Source from the content-addressed store, hash-verified

593
594// ValidateRemoteURL checks that a string is a valid Git remote URL
595func ValidateRemoteURL(remote string) error {
596 u, _ := url.Parse(remote)
597 if u == nil || u.Scheme == "" {
598 // This is either an invalid remote name (maybe the user made a typo
599 // when selecting a named remote) or a bare SSH URL like
600 // "x@y.com:path/to/resource.git". Guess that this is a URL in the latter
601 // form if the string contains a colon ":", and an invalid remote if it
602 // does not.
603 if strings.Contains(remote, ":") {
604 return nil
605 } else {
606 return errors.New(tr.Tr.Get("invalid remote name: %q", remote))
607 }
608 }
609
610 switch u.Scheme {
611 case "ssh", "http", "https", "git", "file":
612 return nil
613 default:
614 return errors.New(tr.Tr.Get("invalid remote URL protocol %q in %q", u.Scheme, remote))
615 }
616}
617
618func RewriteLocalPathAsURL(path string) string {
619 var slash string

Callers 2

ValidateRemoteFromListFunction · 0.85
TestValidateRemoteURLFunction · 0.85

Calls 3

NewFunction · 0.92
ContainsMethod · 0.65
GetMethod · 0.65

Tested by 1

TestValidateRemoteURLFunction · 0.68