summaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-07-28 00:46:34 +0800
committerGitHub <noreply@github.com>2022-07-28 00:46:34 +0800
commit6554d5197fa4082f3058ee880d2d6d80fbd97a56 (patch)
tree950e9da7211f2fb1c521bef699d8985fd499c259 /routers/web/repo
parent3f8752524969c52f573c85ac5007c0e91e02b201 (diff)
downloadgitea-6554d5197fa4082f3058ee880d2d6d80fbd97a56.tar.gz
gitea-6554d5197fa4082f3058ee880d2d6d80fbd97a56.zip
Fix possible panic when repository is empty (#20509)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/view.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index a396be8ae3..1a39b21c6f 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -896,10 +896,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)