aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
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 /modules/context/repo.go
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 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 84e07ab422..b20ea26e4e 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -319,7 +319,14 @@ func EarlyResponseForGoGetMeta(ctx *Context) {
ctx.PlainText(http.StatusBadRequest, "invalid repository path")
return
}
- goImportContent := fmt.Sprintf("%s git %s", ComposeGoGetImport(username, reponame), repo_model.ComposeHTTPSCloneURL(username, reponame))
+
+ var cloneURL string
+ if setting.Repository.GoGetCloneURLProtocol == "ssh" {
+ cloneURL = repo_model.ComposeSSHCloneURL(username, reponame)
+ } else {
+ cloneURL = repo_model.ComposeHTTPSCloneURL(username, reponame)
+ }
+ goImportContent := fmt.Sprintf("%s git %s", ComposeGoGetImport(username, reponame), cloneURL)
htmlMeta := fmt.Sprintf(`<meta name="go-import" content="%s">`, html.EscapeString(goImportContent))
ctx.PlainText(http.StatusOK, htmlMeta)
}