@@ -602,25 +602,23 @@ func ComposeHTTPSCloneURL(owner, repo string) string {
602602
603603func ComposeSSHCloneURL (ownerName , repoName string ) string {
604604 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.
608605 sshDomain := setting .SSH .Domain
609- ip := net .ParseIP (setting .SSH .Domain )
610- if ip != nil && ip .To4 () == nil {
611- sshDomain = "[" + setting .SSH .Domain + "]"
612- }
613606
607+ // non-standard port, it must use full URI
614608 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
619617 }
620618 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 ))
622620 }
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 ))
624622}
625623
626624func (repo * Repository ) cloneLink (isWiki bool ) * CloneLink {
0 commit comments