瀏覽代碼

Fix possible panic when repository is empty (#20509)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
tags/v1.18.0-rc0
Lunny Xiao 1 年之前
父節點
當前提交
6554d5197f
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 8 行新增4 行删除
  1. 8
    4
      routers/web/repo/view.go

+ 8
- 4
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)

Loading…
取消
儲存