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

Function isLocalRemote

internal/diff/git.go:475–492  ·  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

473// rather than a network host: a file:// URL, a POSIX absolute/relative/home
474// path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share).
475func isLocalRemote(s string) bool {
476 switch {
477 case strings.HasPrefix(s, "file://"):
478 return true
479 case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"):
480 return true
481 case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..":
482 return true
483 case strings.HasPrefix(s, `\\`): // UNC \\server\share
484 return true
485 }
486 // Windows drive path: X:\ or X:/. Require a separator after the colon so a
487 // single-letter scp host ("c:path") is not misread — real hosts have a dot.
488 if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') {
489 return true
490 }
491 return false
492}
493
494func isASCIILetter(b byte) bool {
495 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