Skip to content

Commit 4ed32e7

Browse files
authored
Fix possible panic when repository is empty (#20509) (#20526)
Backport #20509
1 parent fa46d66 commit 4ed32e7

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

904904
if ctx.Repo.Repository.IsEmpty {
905-
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
906-
if err != nil {
907-
ctx.ServerError("GitRepo.IsEmpty", err)
908-
return
905+
reallyEmpty := true
906+
var err error
907+
if ctx.Repo.GitRepo != nil {
908+
reallyEmpty, err = ctx.Repo.GitRepo.IsEmpty()
909+
if err != nil {
910+
ctx.ServerError("GitRepo.IsEmpty", err)
911+
return
912+
}
909913
}
910914
if reallyEmpty {
911915
ctx.HTML(http.StatusOK, tplRepoEMPTY)

0 commit comments

Comments
 (0)