diff options
author | Wim <wim@42.be> | 2020-07-26 22:31:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-26 16:31:28 -0400 |
commit | 4609eba2e7683acde13231fb02747e3b2e09ff45 (patch) | |
tree | 42982792623d4a77a9783a7e222a2d98dd329741 /models | |
parent | 415fc8288ff9c83c99939003657db3c6ac978a3e (diff) | |
download | gitea-4609eba2e7683acde13231fb02747e3b2e09ff45.tar.gz gitea-4609eba2e7683acde13231fb02747e3b2e09ff45.zip |
Fix ipv6 parsing (#12321)
* Fix ipv6 parsing
* Update modules/setting/setting.go
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/models/repo.go b/models/repo.go index 36662825c5..b2b6e1a26f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -17,6 +17,7 @@ import ( _ "image/jpeg" "image/png" "io/ioutil" + "net" "net/url" "os" "path" @@ -969,12 +970,21 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink { } cl := new(CloneLink) + + // if we have a ipv6 literal we need to put brackets around it + // for the git cloning to work. + sshDomain := setting.SSH.Domain + ip := net.ParseIP(setting.SSH.Domain) + if ip != nil && ip.To4() == nil { + sshDomain = "[" + setting.SSH.Domain + "]" + } + if setting.SSH.Port != 22 { - cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)), repo.OwnerName, repoName) } else if setting.Repository.UseCompatSSHURI { - cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName) } else { - cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName) + cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName) } cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName) return cl |