aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/common.go
diff options
context:
space:
mode:
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{