ValidateRemoteURL checks that a string is a valid Git remote URL
(remote string)
| 593 | |
| 594 | // ValidateRemoteURL checks that a string is a valid Git remote URL |
| 595 | func 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 | |
| 618 | func RewriteLocalPathAsURL(path string) string { |
| 619 | var slash string |