From c56b33f6e60193e142d5811ce01516be88431d90 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 15 Jan 2023 13:57:11 +0000 Subject: [PATCH] Prevent panic on looking at api "git" endpoints for empty repos The API endpoints for "git" can panic if they are called on an empty repo. We can simply allow empty repos for these endpoints without worry as they should just work. Fix #22452 Signed-off-by: Andrew Thornton --- routers/api/v1/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index c12ceacdd3b16..d5a12ead85fd0 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1061,7 +1061,7 @@ func Routes(ctx gocontext.Context) *web.Route { m.Get("/blobs/{sha}", repo.GetBlob) m.Get("/tags/{sha}", repo.GetAnnotatedTag) m.Get("/notes/{sha}", repo.GetNote) - }, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode)) + }, context.ReferencesGitRepo(true), reqRepoReader(unit.TypeCode)) m.Post("/diffpatch", reqRepoWriter(unit.TypeCode), reqToken(), bind(api.ApplyDiffPatchFileOptions{}), repo.ApplyDiffPatch) m.Group("/contents", func() { m.Get("", repo.GetContentsList)