Fix possible panic when repository is empty (#20509) (#20527)

This commit is contained in:
6543 2022-07-28 21:02:53 +02:00 committed by GitHub
parent eeaa9250e0
commit 9aa13c585e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -856,10 +856,14 @@ func renderCode(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty() reallyEmpty := true
if err != nil { var err error
ctx.ServerError("GitRepo.IsEmpty", err) if ctx.Repo.GitRepo != nil {
return reallyEmpty, err = ctx.Repo.GitRepo.IsEmpty()
if err != nil {
ctx.ServerError("GitRepo.IsEmpty", err)
return
}
} }
if reallyEmpty { if reallyEmpty {
ctx.HTML(http.StatusOK, tplRepoEMPTY) ctx.HTML(http.StatusOK, tplRepoEMPTY)