Skip to content

Commit 26070eb

Browse files
authored
When the git repository on storage is changed, the repository modal should also be updated (#18088)
User would keep seeing an empty repo if: * An error occurs during the first git pushing/receiving * A user replaces the Gitea's empty repository manually Fix: when a user is viewing the repository web page, if the repoModal.IsEmpty is true, we check the git repository again to detect whether it is really empty. However: the IsEmpty flag is deeply broken and should be removed. For example it's possible for a repository to be non-empty by that flag but still 500 because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
1 parent c7151c2 commit 26070eb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

routers/web/repo/view.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,30 @@ func renderCode(ctx *context.Context) {
840840
ctx.Data["PageIsViewCode"] = true
841841

842842
if ctx.Repo.Repository.IsEmpty {
843-
ctx.HTML(http.StatusOK, tplRepoEMPTY)
844-
return
843+
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
844+
if err != nil {
845+
ctx.ServerError("GitRepo.IsEmpty", err)
846+
return
847+
}
848+
if reallyEmpty {
849+
ctx.HTML(http.StatusOK, tplRepoEMPTY)
850+
return
851+
}
852+
// the repo is not really empty, so we should update the modal in database
853+
// such problem may be caused by:
854+
// 1) an error occurs during pushing/receiving. 2) the user replaces an empty git repo manually
855+
// and even more: the IsEmpty flag is deeply broken and should be removed with the UI changed to manage to cope with empty repos.
856+
// it's possible for a repository to be non-empty by that flag but still 500
857+
// because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
858+
ctx.Repo.Repository.IsEmpty = false
859+
if err = repo_model.UpdateRepositoryCols(ctx.Repo.Repository, "is_empty"); err != nil {
860+
ctx.ServerError("UpdateRepositoryCols", err)
861+
return
862+
}
863+
if err = models.UpdateRepoSize(db.DefaultContext, ctx.Repo.Repository); err != nil {
864+
ctx.ServerError("UpdateRepoSize", err)
865+
return
866+
}
845867
}
846868

847869
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name

0 commit comments

Comments
 (0)