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

Function isLocalRemote

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

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

Callers 1

canonicalRemoteFunction · 0.85

Calls 1

isASCIILetterFunction · 0.85

Tested by

no test coverage detected