Fix possible panic when repository is empty (#20509)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
pull/20469/head
Lunny Xiao 2 years ago committed by GitHub
parent 3f87525249
commit 6554d5197f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      routers/web/repo/view.go

@ -896,11 +896,15 @@ func renderCode(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsEmpty {
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
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)
return

Loading…
Cancel
Save