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

Function isLocalRemote

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

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