Skip to content

Commit 5aeecf4

Browse files
lunnywxiaoguang
authored and
Sysoev, Vladimir
committed
Fix possible panic when repository is empty (go-gitea#20509)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 6deb6ec commit 5aeecf4

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
@@ -896,10 +896,14 @@ func renderCode(ctx *context.Context) {
896896
ctx.Data["PageIsViewCode"] = true
897897

898898
if ctx.Repo.Repository.IsEmpty {
899-
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
900-
if err != nil {
901-
ctx.ServerError("GitRepo.IsEmpty", err)
902-
return
899+
reallyEmpty := true
900+
var err error
901+
if ctx.Repo.GitRepo != nil {
902+
reallyEmpty, err = ctx.Repo.GitRepo.IsEmpty()
903+
if err != nil {
904+
ctx.ServerError("GitRepo.IsEmpty", err)
905+
return
906+
}
903907
}
904908
if reallyEmpty {
905909
ctx.HTML(http.StatusOK, tplRepoEMPTY)

0 commit comments

Comments
 (0)