This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -187,15 +187,22 @@ func (e urlEndpoint) Path() string {
187187type scpEndpoint struct {
188188 user string
189189 host string
190+ port string
190191 path string
191192}
192193
193194func (e * scpEndpoint ) Protocol () string { return "ssh" }
194195func (e * scpEndpoint ) User () string { return e .user }
195196func (e * scpEndpoint ) Password () string { return "" }
196197func (e * scpEndpoint ) Host () string { return e .host }
197- func (e * scpEndpoint ) Port () int { return 22 }
198198func (e * scpEndpoint ) Path () string { return e .path }
199+ func (e * scpEndpoint ) Port () int {
200+ i , err := strconv .Atoi (e .port )
201+ if err != nil {
202+ return 22
203+ }
204+ return i
205+ }
199206
200207func (e * scpEndpoint ) String () string {
201208 var user string
@@ -220,7 +227,7 @@ func (e *fileEndpoint) String() string { return e.path }
220227
221228var (
222229 isSchemeRegExp = regexp .MustCompile (`^[^:]+://` )
223- scpLikeUrlRegExp = regexp .MustCompile (`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?P<path>[^\\].*)$` )
230+ scpLikeUrlRegExp = regexp .MustCompile (`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})/)?(? P<path>[^\\].*)$` )
224231)
225232
226233func parseSCPLike (endpoint string ) (Endpoint , bool ) {
@@ -232,7 +239,8 @@ func parseSCPLike(endpoint string) (Endpoint, bool) {
232239 return & scpEndpoint {
233240 user : m [1 ],
234241 host : m [2 ],
235- path : m [3 ],
242+ port : m [3 ],
243+ path : m [4 ],
236244 }, true
237245}
238246
Original file line number Diff line number Diff line change @@ -74,6 +74,18 @@ func (s *SuiteCommon) TestNewEndpointSCPLike(c *C) {
7474 c .Assert (e .String (), Equals , "git@github.com:user/repository.git" )
7575}
7676
77+ func (s * SuiteCommon ) TestNewEndpointSCPLikeWithPort (c * C ) {
78+ e , err := NewEndpoint ("git@github.com:9999/user/repository.git" )
79+ c .Assert (err , IsNil )
80+ c .Assert (e .Protocol (), Equals , "ssh" )
81+ c .Assert (e .User (), Equals , "git" )
82+ c .Assert (e .Password (), Equals , "" )
83+ c .Assert (e .Host (), Equals , "github.com" )
84+ c .Assert (e .Port (), Equals , 9999 )
85+ c .Assert (e .Path (), Equals , "user/repository.git" )
86+ c .Assert (e .String (), Equals , "git@github.com:user/repository.git" )
87+ }
88+
7789func (s * SuiteCommon ) TestNewEndpointFileAbs (c * C ) {
7890 e , err := NewEndpoint ("/foo.git" )
7991 c .Assert (err , IsNil )
You can’t perform that action at this time.
0 commit comments