summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorrune <runner.mei@gmail.com>2023-05-12 17:44:37 +0800
committerGitHub <noreply@github.com>2023-05-12 09:44:37 +0000
commit4b808133414e39348f56d691883426947bf2d322 (patch)
treece7dc40af8630e9e9db07f500dd56e032cdc00ba /models
parent49808136c5af5946851c5486d4630482d79eff8b (diff)
downloadgitea-4b808133414e39348f56d691883426947bf2d322.tar.gz
gitea-4b808133414e39348f56d691883426947bf2d322.zip
Support SSH for go get (#24664)
fix #12192 Support SSH for go get --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: mfk <mfk@hengwei.com.cn> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'models')
-rw-r--r--models/repo/repo.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go
index 2e8c28cbb3..7cbd5867b7 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -547,16 +547,9 @@ func ComposeHTTPSCloneURL(owner, repo string) string {
return fmt.Sprintf("%s%s/%s.git", setting.AppURL, url.PathEscape(owner), url.PathEscape(repo))
}
-func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
- repoName := repo.Name
- if isWiki {
- repoName += ".wiki"
- }
-
+func ComposeSSHCloneURL(ownerName, repoName string) string {
sshUser := setting.SSH.User
- 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
@@ -566,12 +559,25 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
}
if setting.SSH.Port != 22 {
- cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)), url.PathEscape(repo.OwnerName), url.PathEscape(repoName))
- } else if setting.Repository.UseCompatSSHURI {
- cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, url.PathEscape(repo.OwnerName), url.PathEscape(repoName))
- } else {
- cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, url.PathEscape(repo.OwnerName), url.PathEscape(repoName))
+ return fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser,
+ net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)),
+ url.PathEscape(ownerName),
+ url.PathEscape(repoName))
+ }
+ if setting.Repository.UseCompatSSHURI {
+ return fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, url.PathEscape(ownerName), url.PathEscape(repoName))
}
+ return fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, url.PathEscape(ownerName), url.PathEscape(repoName))
+}
+
+func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
+ repoName := repo.Name
+ if isWiki {
+ repoName += ".wiki"
+ }
+
+ cl := new(CloneLink)
+ cl.SSH = ComposeSSHCloneURL(repo.OwnerName, repoName)
cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName)
return cl
}