From ec896dfad30d016d9d9a53282628cbb716827bdf Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 20 Apr 2017 15:18:42 +0800 Subject: [PATCH 1/3] fix go get sub package and add domain on installation to let go get work defaultly --- routers/install.go | 1 + routers/repo/http.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/routers/install.go b/routers/install.go index b4df536d0ccd2..1ab409d00d24e 100644 --- a/routers/install.go +++ b/routers/install.go @@ -257,6 +257,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath) cfg.Section("").Key("RUN_USER").SetValue(form.RunUser) cfg.Section("server").Key("SSH_DOMAIN").SetValue(form.Domain) + cfg.Section("server").Key("DOMAIN").SetValue(form.Domain) cfg.Section("server").Key("HTTP_PORT").SetValue(form.HTTPPort) cfg.Section("server").Key("ROOT_URL").SetValue(form.AppURL) diff --git a/routers/repo/http.go b/routers/repo/http.go index 12fcbcfb3fcd3..f0466e6576aa8 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -17,6 +17,8 @@ import ( "strings" "time" + "github.com/Unknwon/com" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -24,11 +26,33 @@ import ( "code.gitea.io/gitea/modules/setting" ) +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) { + ctx.PlainText(200, []byte(com.Expand(``, + map[string]string{ + "GoGetImport": composeGoGetImport(ctx.Params(":username"), ctx.Params(":reponame"), ctx.Params("*")), + "CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")), + }))) +} + // HTTP implmentation git smart HTTP protocol func HTTP(ctx *context.Context) { username := ctx.Params(":username") reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") + if ctx.Query("go-get") == "1" { + earlyResponseForGoGetMeta(ctx) + return + } + var isPull bool service := ctx.Query("service") if service == "git-receive-pack" || From 2096e0e1521719a0269356d20a54e4e6b654f89b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 20 Apr 2017 16:12:33 +0800 Subject: [PATCH 2/3] fix import sequence --- routers/repo/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/repo/http.go b/routers/repo/http.go index f0466e6576aa8..f2f709fcb0bb9 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -17,13 +17,13 @@ import ( "strings" "time" - "github.com/Unknwon/com" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "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 { From 700af95dbd0dd9cf79e0eb7320e0b248b8a68645 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 21 Apr 2017 10:02:52 +0800 Subject: [PATCH 3/3] fix .git problem --- modules/context/repo.go | 2 +- routers/repo/http.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index aae76185e2016..4deae2ebba8e5 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -127,7 +127,7 @@ func composeGoGetImport(owner, repo string) string { func earlyResponseForGoGetMeta(ctx *Context) { ctx.PlainText(200, []byte(com.Expand(``, map[string]string{ - "GoGetImport": composeGoGetImport(ctx.Params(":username"), ctx.Params(":reponame")), + "GoGetImport": composeGoGetImport(ctx.Params(":username"), strings.TrimSuffix(ctx.Params(":reponame"), ".git")), "CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")), }))) } diff --git a/routers/repo/http.go b/routers/repo/http.go index f2f709fcb0bb9..9c2ec4d029558 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -35,11 +35,11 @@ func composeGoGetImport(owner, repo, sub string) string { // 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) { +func earlyResponseForGoGetMeta(ctx *context.Context, username, reponame, subpath string) { ctx.PlainText(200, []byte(com.Expand(``, map[string]string{ - "GoGetImport": composeGoGetImport(ctx.Params(":username"), ctx.Params(":reponame"), ctx.Params("*")), - "CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")), + "GoGetImport": composeGoGetImport(username, reponame, subpath), + "CloneLink": models.ComposeHTTPSCloneURL(username, reponame), }))) } @@ -47,9 +47,10 @@ func earlyResponseForGoGetMeta(ctx *context.Context) { 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) + earlyResponseForGoGetMeta(ctx, username, reponame, subpath) return }