aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/common.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-04-28 15:20:51 +0200
committerSantiago M. Mola <santi@mola.io>2017-04-28 16:33:31 +0200
commit4a670e130804d630fa056e4a60101698dc7a9af1 (patch)
tree289fed4a798d9e3c7bdc633970109d8a7a856737 /plumbing/transport/common.go
parent727bf94da8e3cebd3ff467d30425b12d671fbca7 (diff)
downloadgo-git-4a670e130804d630fa056e4a60101698dc7a9af1.tar.gz
do not convert local paths to URL
* Do not convert local paths to URLs, just keep them as they are. * This way we add support for Windows without taking care of Windows path-to-URL conversion.
Diffstat (limited to 'plumbing/transport/common.go')
-rw-r--r--plumbing/transport/common.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go
index 0ff9e89..d6594ca 100644
--- a/plumbing/transport/common.go
+++ b/plumbing/transport/common.go
@@ -114,6 +114,10 @@ func NewEndpoint(endpoint string) (Endpoint, error) {
return e, nil
}
+ if e, ok := parseFile(endpoint); ok {
+ return e, nil
+ }
+
u, err := url.Parse(endpoint)
if err != nil {
return nil, plumbing.NewPermanentError(err)
@@ -201,9 +205,21 @@ func (e *scpEndpoint) String() string {
return fmt.Sprintf("%s%s:%s", user, e.host, e.path)
}
+type fileEndpoint struct {
+ path string
+}
+
+func (e *fileEndpoint) Protocol() string { return "file" }
+func (e *fileEndpoint) User() string { return "" }
+func (e *fileEndpoint) Password() string { return "" }
+func (e *fileEndpoint) Host() string { return "" }
+func (e *fileEndpoint) Port() int { return 0 }
+func (e *fileEndpoint) Path() string { return e.path }
+func (e *fileEndpoint) String() string { return e.path }
+
var (
- isSchemeRegExp = regexp.MustCompile("^[^:]+://")
- scpLikeUrlRegExp = regexp.MustCompile("^(?:(?P<user>[^@]+)@)?(?P<host>[^:]+):/?(?P<path>.+)$")
+ isSchemeRegExp = regexp.MustCompile(`^[^:]+://`)
+ scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?P<path>[^\\].*)$`)
)
func parseSCPLike(endpoint string) (Endpoint, bool) {
@@ -219,6 +235,15 @@ func parseSCPLike(endpoint string) (Endpoint, bool) {
}, true
}
+func parseFile(endpoint string) (Endpoint, bool) {
+ if isSchemeRegExp.MatchString(endpoint) {
+ return nil, false
+ }
+
+ path := endpoint
+ return &fileEndpoint{path}, true
+}
+
// UnsupportedCapabilities are the capabilities not supported by any client
// implementation
var UnsupportedCapabilities = []capability.Capability{