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

Function isLocalRemote

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

491// rather than a network host: a file:// URL, a POSIX absolute/relative/home
492// path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share).
493func isLocalRemote(s string) bool {
494 switch {
495 case strings.HasPrefix(s, "file://"):
496 return true
497 case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"):
498 return true
499 case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..":
500 return true
501 case strings.HasPrefix(s, `\\`): // UNC \\server\share
502 return true
503 }
504 // Windows drive path: X:\ or X:/. Require a separator after the colon so a
505 // single-letter scp host ("c:path") is not misread — real hosts have a dot.
506 if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') {
507 return true
508 }
509 return false
510}
511
512func isASCIILetter(b byte) bool {
513 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