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