aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 02:09:02 +0200
committerGitHub <noreply@github.com>2017-05-04 02:09:02 +0200
commitc00e46e225a9974a0e6440765bbea548352183bc (patch)
tree4fe04df1602363cae392c6943fea844fdf9a9b0a /plumbing/transport/common.go
parentd95e4a5b1dce0ba5fa25e5535044c05088b79e16 (diff)
parent4a670e130804d630fa056e4a60101698dc7a9af1 (diff)
downloadgo-git-c00e46e225a9974a0e6440765bbea548352183bc.tar.gz
Merge pull request #368 from smola/windows-path
do not convert local paths to URL
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{