aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-09-29 21:45:44 +0200
committerGitHub <noreply@github.com>2017-09-29 21:45:44 +0200
commit30a99a264355ff1125c5464ad72965e927b1baea (patch)
tree01dfffe8aa9f45eb962e22d6cab96fcf0a905767
parent7d1595faba108f5c6c9b678288eb5092ba555bd1 (diff)
parent0ddf8f55a4afbe4d56bbd3fc8546622f7b9b1872 (diff)
downloadgo-git-30a99a264355ff1125c5464ad72965e927b1baea.tar.gz
Merge pull request #608 from balkian/master
Add port to SCP Endpoints
-rw-r--r--plumbing/transport/common.go14
-rw-r--r--plumbing/transport/common_test.go12
2 files changed, 23 insertions, 3 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go
index 2088500..ac71bb3 100644
--- a/plumbing/transport/common.go
+++ b/plumbing/transport/common.go
@@ -187,6 +187,7 @@ func (e urlEndpoint) Path() string {
type scpEndpoint struct {
user string
host string
+ port string
path string
}
@@ -194,8 +195,14 @@ func (e *scpEndpoint) Protocol() string { return "ssh" }
func (e *scpEndpoint) User() string { return e.user }
func (e *scpEndpoint) Password() string { return "" }
func (e *scpEndpoint) Host() string { return e.host }
-func (e *scpEndpoint) Port() int { return 22 }
func (e *scpEndpoint) Path() string { return e.path }
+func (e *scpEndpoint) Port() int {
+ i, err := strconv.Atoi(e.port)
+ if err != nil {
+ return 22
+ }
+ return i
+}
func (e *scpEndpoint) String() string {
var user string
@@ -220,7 +227,7 @@ func (e *fileEndpoint) String() string { return e.path }
var (
isSchemeRegExp = regexp.MustCompile(`^[^:]+://`)
- scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?P<path>[^\\].*)$`)
+ scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})/)?(?P<path>[^\\].*)$`)
)
func parseSCPLike(endpoint string) (Endpoint, bool) {
@@ -232,7 +239,8 @@ func parseSCPLike(endpoint string) (Endpoint, bool) {
return &scpEndpoint{
user: m[1],
host: m[2],
- path: m[3],
+ port: m[3],
+ path: m[4],
}, true
}
diff --git a/plumbing/transport/common_test.go b/plumbing/transport/common_test.go
index ec617bd..52759e6 100644
--- a/plumbing/transport/common_test.go
+++ b/plumbing/transport/common_test.go
@@ -74,6 +74,18 @@ func (s *SuiteCommon) TestNewEndpointSCPLike(c *C) {
c.Assert(e.String(), Equals, "git@github.com:user/repository.git")
}
+func (s *SuiteCommon) TestNewEndpointSCPLikeWithPort(c *C) {
+ e, err := NewEndpoint("git@github.com:9999/user/repository.git")
+ c.Assert(err, IsNil)
+ c.Assert(e.Protocol(), Equals, "ssh")
+ c.Assert(e.User(), Equals, "git")
+ c.Assert(e.Password(), Equals, "")
+ c.Assert(e.Host(), Equals, "github.com")
+ c.Assert(e.Port(), Equals, 9999)
+ c.Assert(e.Path(), Equals, "user/repository.git")
+ c.Assert(e.String(), Equals, "git@github.com:user/repository.git")
+}
+
func (s *SuiteCommon) TestNewEndpointFileAbs(c *C) {
e, err := NewEndpoint("/foo.git")
c.Assert(err, IsNil)