MCPcopy Create free account
hub / github.com/alibaba/open-code-review / isLocalRemote

Function isLocalRemote

internal/diff/git.go:560–577  ·  view source on GitHub ↗

isLocalRemote reports whether a remote URL points at the local filesystem rather than a network host: a file:// URL, a POSIX absolute/relative/home path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share).

(s string)

Source from the content-addressed store, hash-verified

558// rather than a network host: a file:// URL, a POSIX absolute/relative/home
559// path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share).
560func isLocalRemote(s string) bool {
561 switch {
562 case strings.HasPrefix(s, "file://"):
563 return true
564 case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"):
565 return true
566 case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..":
567 return true
568 case strings.HasPrefix(s, `\\`): // UNC \\server\share
569 return true
570 }
571 // Windows drive path: X:\ or X:/. Require a separator after the colon so a
572 // single-letter scp host ("c:path") is not misread — real hosts have a dot.
573 if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') {
574 return true
575 }
576 return false
577}
578
579func isASCIILetter(b byte) bool {
580 return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')

Callers 1

canonicalRemoteFunction · 0.85

Calls 1

isASCIILetterFunction · 0.70

Tested by

no test coverage detected