Skip to content

Commit

Permalink
fix go get sub package and add domain on installation to let go get w…
Browse files Browse the repository at this point in the history
…ork defaultly (#1518)

* fix go get sub package and add domain on installation to let go get work defaultly

* fix import sequence

* fix .git problem
  • Loading branch information
lunny authored Apr 21, 2017
1 parent 4207278 commit f0db3da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func composeGoGetImport(owner, repo string) string {
func earlyResponseForGoGetMeta(ctx *Context) {
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
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")),
})))
}
Expand Down
1 change: 1 addition & 0 deletions routers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions routers/repo/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,37 @@ 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)
return
}

var isPull bool
service := ctx.Query("service")
Expand Down

0 comments on commit f0db3da

Please sign in to comment.