aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLunny Xiao2017-09-23 21:58:17 +0800
committerLauris BH2017-09-23 16:58:17 +0300
commit03ff7687e02b86b956fffc74fb2ab66430cd96d1 (patch)
tree4ff16056464bcb4e7aae4be2f3b02376354dd5ca
parentf646154eadf7478b9e097cb314016dd946b243ef (diff)
fix go get subpackage bug (#2584) (#2589)v1.2.0-rc3
* fix go get subpackage bug * merge the duplicated funtions
-rw-r--r--modules/context/repo.go24
-rw-r--r--routers/repo/http.go22
2 files changed, 14 insertions, 32 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index f790dfa92..98bc7de0d 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -124,21 +124,23 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
}
}
-// composeGoGetImport returns go-get-import meta content.
-func composeGoGetImport(owner, repo string) string {
+// ComposeGoGetImport returns go-get-import meta content.
+func ComposeGoGetImport(owner, repo string) string {
return path.Join(setting.Domain, setting.AppSubURL, owner, repo)
}
-// earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
+// EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200
// if user does not have actual access to the requested repository,
// or the owner or repository does not exist at all.
// This is particular a workaround for "go get" command which does not respect
// .netrc file.
-func earlyResponseForGoGetMeta(ctx *Context) {
+func EarlyResponseForGoGetMeta(ctx *Context) {
+ username := ctx.Params(":username")
+ reponame := ctx.Params(":reponame")
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
map[string]string{
- "GoGetImport": composeGoGetImport(ctx.Params(":username"), strings.TrimSuffix(ctx.Params(":reponame"), ".git")),
- "CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")),
+ "GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")),
+ "CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
})))
}
@@ -206,7 +208,7 @@ func RepoIDAssignment() macaron.Handler {
// Check access.
if ctx.Repo.AccessMode == models.AccessModeNone {
if ctx.Query("go-get") == "1" {
- earlyResponseForGoGetMeta(ctx)
+ EarlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "no access right", err)
@@ -250,7 +252,7 @@ func RepoAssignment() macaron.Handler {
if err != nil {
if models.IsErrUserNotExist(err) {
if ctx.Query("go-get") == "1" {
- earlyResponseForGoGetMeta(ctx)
+ EarlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "GetUserByName", nil)
@@ -272,7 +274,7 @@ func RepoAssignment() macaron.Handler {
RedirectToRepo(ctx, redirectRepoID)
} else if models.IsErrRepoRedirectNotExist(err) {
if ctx.Query("go-get") == "1" {
- earlyResponseForGoGetMeta(ctx)
+ EarlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "GetRepositoryByName", nil)
@@ -305,7 +307,7 @@ func RepoAssignment() macaron.Handler {
// Check access.
if ctx.Repo.AccessMode == models.AccessModeNone {
if ctx.Query("go-get") == "1" {
- earlyResponseForGoGetMeta(ctx)
+ EarlyResponseForGoGetMeta(ctx)
return
}
ctx.Handle(404, "no access right", err)
@@ -433,7 +435,7 @@ func RepoAssignment() macaron.Handler {
ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
if ctx.Query("go-get") == "1" {
- ctx.Data["GoGetImport"] = composeGoGetImport(owner.Name, repo.Name)
+ ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName)
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 4265c80ac..3f6839ee3 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -22,35 +22,15 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
-
- "github.com/Unknwon/com"
)
-func composeGoGetImport(owner, repo, sub string) string {
- return path.Join(setting.Domain, setting.AppSubURL, owner, repo, sub)
-}
-
-// earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
-// if user does not have actual access to the requested repository,
-// or the owner or repository does not exist at all.
-// This is particular a workaround for "go get" command which does not respect
-// .netrc file.
-func earlyResponseForGoGetMeta(ctx *context.Context, username, reponame, subpath string) {
- ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
- map[string]string{
- "GoGetImport": composeGoGetImport(username, reponame, subpath),
- "CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
- })))
-}
-
// HTTP implmentation git smart HTTP protocol
func HTTP(ctx *context.Context) {
username := ctx.Params(":username")
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
- subpath := ctx.Params("*")
if ctx.Query("go-get") == "1" {
- earlyResponseForGoGetMeta(ctx, username, reponame, subpath)
+ context.EarlyResponseForGoGetMeta(ctx)
return
}