Skip to content

Commit 4bd4a7c

Browse files
committed
Remove duplicated permission check for git http and move repository redirect after necessary checking
1 parent 3c95b07 commit 4bd4a7c

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

routers/web/githttp.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,12 @@
44
package web
55

66
import (
7-
"net/http"
8-
9-
"code.gitea.io/gitea/modules/setting"
107
"code.gitea.io/gitea/modules/web"
118
"code.gitea.io/gitea/routers/web/repo"
129
"code.gitea.io/gitea/services/context"
1310
)
1411

1512
func addOwnerRepoGitHTTPRouters(m *web.Router) {
16-
reqGitSignIn := func(ctx *context.Context) {
17-
if !setting.Service.RequireSignInView {
18-
return
19-
}
20-
// rely on the results of Contexter
21-
if !ctx.IsSigned {
22-
// TODO: support digit auth - which would be Authorization header with digit
23-
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
24-
ctx.HTTPError(http.StatusUnauthorized)
25-
}
26-
}
2713
m.Group("/{username}/{reponame}", func() {
2814
m.Methods("POST,OPTIONS", "/git-upload-pack", repo.ServiceUploadPack)
2915
m.Methods("POST,OPTIONS", "/git-receive-pack", repo.ServiceReceivePack)
@@ -36,5 +22,5 @@ func addOwnerRepoGitHTTPRouters(m *web.Router) {
3622
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
3723
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
3824
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
39-
}, optSignInIgnoreCsrf, reqGitSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
25+
}, optSignInIgnoreCsrf, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
4026
}

routers/web/repo/githttp.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ func CorsHandler() func(next http.Handler) http.Handler {
5757

5858
// httpBase implementation git smart HTTP protocol
5959
func httpBase(ctx *context.Context) *serviceHandler {
60-
username := ctx.PathParam("username")
61-
reponame := strings.TrimSuffix(ctx.PathParam("reponame"), ".git")
62-
6360
if ctx.FormString("go-get") == "1" {
6461
context.EarlyResponseForGoGetMeta(ctx)
6562
return nil
@@ -90,6 +87,8 @@ func httpBase(ctx *context.Context) *serviceHandler {
9087

9188
isWiki := false
9289
unitType := unit.TypeCode
90+
username := ctx.PathParam("username")
91+
reponame := strings.TrimSuffix(ctx.PathParam("reponame"), ".git")
9392

9493
if strings.HasSuffix(reponame, ".wiki") {
9594
isWiki = true
@@ -110,11 +109,6 @@ func httpBase(ctx *context.Context) *serviceHandler {
110109
ctx.ServerError("GetRepositoryByName", err)
111110
return nil
112111
}
113-
114-
if redirectRepoID, err := repo_model.LookupRedirect(ctx, owner.ID, reponame); err == nil {
115-
context.RedirectToRepo(ctx.Base, redirectRepoID)
116-
return nil
117-
}
118112
repoExist = false
119113
}
120114

@@ -243,6 +237,13 @@ func httpBase(ctx *context.Context) *serviceHandler {
243237
}
244238

245239
if !repoExist {
240+
// if repository does not exist, maybe it is renamed to another repository
241+
if redirectRepoID, err := repo_model.LookupRedirect(ctx, owner.ID, reponame); err == nil {
242+
// FIXME: should the user be allowed to know the new name?
243+
context.RedirectToRepo(ctx.Base, redirectRepoID)
244+
return nil
245+
}
246+
246247
if !receivePack {
247248
ctx.PlainText(http.StatusNotFound, "Repository not found")
248249
return nil

0 commit comments

Comments
 (0)