Skip to content

Commit

Permalink
Fix possible panic when repository is empty (#20509)
Browse files Browse the repository at this point in the history
Co-authored-by: wxiaoguang <[email protected]>
  • Loading branch information
lunny and wxiaoguang committed Jul 27, 2022
1 parent 3f87525 commit 6554d51
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6554d51

Please sign in to comment.