Skip to content

Commit 6554d51

Browse files
lunnywxiaoguang
andauthored
Fix possible panic when repository is empty (go-gitea#20509)
Co-authored-by: wxiaoguang <[email protected]>
1 parent 3f87525 commit 6554d51

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

routers/web/repo/view.go

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