Skip to content

Commit cb7af7e

Browse files
6543AbdulrhmnGhanem
authored andcommitted
Use middleware to open gitRepo (go-gitea#19559)
1 parent bc7f7f2 commit cb7af7e

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ func Routes() *web.Route {
10151015
m.Group("/{ref}", func() {
10161016
m.Get("/status", repo.GetCombinedCommitStatusByRef)
10171017
m.Get("/statuses", repo.GetCommitStatusesByRef)
1018-
})
1018+
}, context.ReferencesGitRepo())
10191019
}, reqRepoReader(unit.TypeCode))
10201020
m.Group("/git", func() {
10211021
m.Group("/commits", func() {

routers/api/v1/utils/git.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package utils
66

77
import (
8+
"fmt"
89
"net/http"
910

1011
"code.gitea.io/gitea/modules/context"
@@ -35,12 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
3536
// GetGitRefs return git references based on filter
3637
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
3738
if ctx.Repo.GitRepo == nil {
38-
var err error
39-
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
40-
if err != nil {
41-
return nil, "OpenRepository", err
42-
}
43-
defer ctx.Repo.GitRepo.Close()
39+
return nil, "", fmt.Errorf("no open git repo found in context")
4440
}
4541
if len(filter) > 0 {
4642
filter = "refs/" + filter

0 commit comments

Comments
 (0)