Skip to content

Commit f0db3da

Browse files
authored
fix go get sub package and add domain on installation to let go get work defaultly (#1518)
* fix go get sub package and add domain on installation to let go get work defaultly * fix import sequence * fix .git problem
1 parent 4207278 commit f0db3da

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

modules/context/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func composeGoGetImport(owner, repo string) string {
127127
func earlyResponseForGoGetMeta(ctx *Context) {
128128
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
129129
map[string]string{
130-
"GoGetImport": composeGoGetImport(ctx.Params(":username"), ctx.Params(":reponame")),
130+
"GoGetImport": composeGoGetImport(ctx.Params(":username"), strings.TrimSuffix(ctx.Params(":reponame"), ".git")),
131131
"CloneLink": models.ComposeHTTPSCloneURL(ctx.Params(":username"), ctx.Params(":reponame")),
132132
})))
133133
}

routers/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
257257
cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath)
258258
cfg.Section("").Key("RUN_USER").SetValue(form.RunUser)
259259
cfg.Section("server").Key("SSH_DOMAIN").SetValue(form.Domain)
260+
cfg.Section("server").Key("DOMAIN").SetValue(form.Domain)
260261
cfg.Section("server").Key("HTTP_PORT").SetValue(form.HTTPPort)
261262
cfg.Section("server").Key("ROOT_URL").SetValue(form.AppURL)
262263

routers/repo/http.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,37 @@ import (
2222
"code.gitea.io/gitea/modules/context"
2323
"code.gitea.io/gitea/modules/log"
2424
"code.gitea.io/gitea/modules/setting"
25+
26+
"github.com/Unknwon/com"
2527
)
2628

29+
func composeGoGetImport(owner, repo, sub string) string {
30+
return path.Join(setting.Domain, setting.AppSubURL, owner, repo, sub)
31+
}
32+
33+
// earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
34+
// if user does not have actual access to the requested repository,
35+
// or the owner or repository does not exist at all.
36+
// This is particular a workaround for "go get" command which does not respect
37+
// .netrc file.
38+
func earlyResponseForGoGetMeta(ctx *context.Context, username, reponame, subpath string) {
39+
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
40+
map[string]string{
41+
"GoGetImport": composeGoGetImport(username, reponame, subpath),
42+
"CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
43+
})))
44+
}
45+
2746
// HTTP implmentation git smart HTTP protocol
2847
func HTTP(ctx *context.Context) {
2948
username := ctx.Params(":username")
3049
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
50+
subpath := ctx.Params("*")
51+
52+
if ctx.Query("go-get") == "1" {
53+
earlyResponseForGoGetMeta(ctx, username, reponame, subpath)
54+
return
55+
}
3156

3257
var isPull bool
3358
service := ctx.Query("service")

0 commit comments

Comments
 (0)