@@ -602,25 +602,23 @@ func ComposeHTTPSCloneURL(owner, repo string) string {
602
602
603
603
func ComposeSSHCloneURL (ownerName , repoName string ) string {
604
604
sshUser := setting .SSH .User
605
-
606
- // if we have a ipv6 literal we need to put brackets around it
607
- // for the git cloning to work.
608
605
sshDomain := setting .SSH .Domain
609
- ip := net .ParseIP (setting .SSH .Domain )
610
- if ip != nil && ip .To4 () == nil {
611
- sshDomain = "[" + setting .SSH .Domain + "]"
612
- }
613
606
607
+ // non-standard port, it must use full URI
614
608
if setting .SSH .Port != 22 {
615
- return fmt .Sprintf ("ssh://%s@%s/%s/%s.git" , sshUser ,
616
- net .JoinHostPort (setting .SSH .Domain , strconv .Itoa (setting .SSH .Port )),
617
- url .PathEscape (ownerName ),
618
- url .PathEscape (repoName ))
609
+ sshHost := net .JoinHostPort (sshDomain , strconv .Itoa (setting .SSH .Port ))
610
+ return fmt .Sprintf ("ssh://%s@%s/%s/%s.git" , sshUser , sshHost , url .PathEscape (ownerName ), url .PathEscape (repoName ))
611
+ }
612
+
613
+ // for standard port, it can use a shorter URI (without the port)
614
+ sshHost := sshDomain
615
+ if ip := net .ParseIP (sshHost ); ip != nil && ip .To4 () == nil {
616
+ sshHost = "[" + sshHost + "]" // for IPv6 address, wrap it with brackets
619
617
}
620
618
if setting .Repository .UseCompatSSHURI {
621
- return fmt .Sprintf ("ssh://%s@%s/%s/%s.git" , sshUser , sshDomain , url .PathEscape (ownerName ), url .PathEscape (repoName ))
619
+ return fmt .Sprintf ("ssh://%s@%s/%s/%s.git" , sshUser , sshHost , url .PathEscape (ownerName ), url .PathEscape (repoName ))
622
620
}
623
- return fmt .Sprintf ("%s@%s:%s/%s.git" , sshUser , sshDomain , url .PathEscape (ownerName ), url .PathEscape (repoName ))
621
+ return fmt .Sprintf ("%s@%s:%s/%s.git" , sshUser , sshHost , url .PathEscape (ownerName ), url .PathEscape (repoName ))
624
622
}
625
623
626
624
func (repo * Repository ) cloneLink (isWiki bool ) * CloneLink {
0 commit comments