@@ -606,25 +606,23 @@ func ComposeHTTPSCloneURL(owner, repo string) string {
606606
607607func ComposeSSHCloneURL (ownerName , repoName string ) string {
608608 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.
612609 sshDomain := setting .SSH .Domain
613- ip := net .ParseIP (setting .SSH .Domain )
614- if ip != nil && ip .To4 () == nil {
615- sshDomain = "[" + setting .SSH .Domain + "]"
616- }
617610
611+ // non-standard port, it must use full URI
618612 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
623621 }
624622 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 ))
626624 }
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 ))
628626}
629627
630628func (repo * Repository ) cloneLink (isWiki bool ) * CloneLink {
0 commit comments