Skip to content

Commit b444c8b

Browse files
lunnywxiaoguang
authored andcommitted
Fix possible panic when repository is empty (go-gitea#20509)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent eeaa925 commit b444c8b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

routers/web/repo/view.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,14 @@ func renderCode(ctx *context.Context) {
856856
ctx.Data["PageIsViewCode"] = true
857857

858858
if ctx.Repo.Repository.IsEmpty {
859-
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
860-
if err != nil {
861-
ctx.ServerError("GitRepo.IsEmpty", err)
862-
return
859+
reallyEmpty := true
860+
var err error
861+
if ctx.Repo.GitRepo != nil {
862+
reallyEmpty, err = ctx.Repo.GitRepo.IsEmpty()
863+
if err != nil {
864+
ctx.ServerError("GitRepo.IsEmpty", err)
865+
return
866+
}
863867
}
864868
if reallyEmpty {
865869
ctx.HTML(http.StatusOK, tplRepoEMPTY)

0 commit comments

Comments
 (0)