From 4ed32e79b6e39ad2f9bf8d95423bebc044a7cd67 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 28 Jul 2022 22:18:49 +0200 Subject: [PATCH] Fix possible panic when repository is empty (#20509) (#20526) Backport #20509 --- routers/web/repo/view.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 169c6fa82d..33a5dec854 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -902,10 +902,14 @@ func renderCode(ctx *context.Context) { ctx.Data["PageIsViewCode"] = true if ctx.Repo.Repository.IsEmpty { - reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty() - if err != nil { - ctx.ServerError("GitRepo.IsEmpty", err) - return + reallyEmpty := true + var err error + if ctx.Repo.GitRepo != nil { + reallyEmpty, err = ctx.Repo.GitRepo.IsEmpty() + if err != nil { + ctx.ServerError("GitRepo.IsEmpty", err) + return + } } if reallyEmpty { ctx.HTML(http.StatusOK, tplRepoEMPTY)