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