summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-12-24 23:36:26 +0800
committerGitHub <noreply@github.com>2021-12-24 23:36:26 +0800
commit26070eb818a09e7123c178434e73c9def88ea8e7 (patch)
tree356a4b91e9832ec7fa4a920dd4df1c4ab83a85c2 /routers
parentc7151c2fb6c91d6d3263af3e8baac73fbeaecbbc (diff)
downloadgitea-26070eb818a09e7123c178434e73c9def88ea8e7.tar.gz
gitea-26070eb818a09e7123c178434e73c9def88ea8e7.zip
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.
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/view.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 45d5a650ba..384681caf6 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -840,8 +840,30 @@ func renderCode(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsEmpty {
- ctx.HTML(http.StatusOK, tplRepoEMPTY)
- return
+ reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
+ if err != nil {
+ ctx.ServerError("GitRepo.IsEmpty", err)
+ return
+ }
+ if reallyEmpty {
+ ctx.HTML(http.StatusOK, tplRepoEMPTY)
+ return
+ }
+ // the repo is not really empty, so we should update the modal in database
+ // such problem may be caused by:
+ // 1) an error occurs during pushing/receiving. 2) the user replaces an empty git repo manually
+ // and even more: the IsEmpty flag is deeply broken and should be removed with the UI changed to manage to cope with empty repos.
+ // 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.
+ ctx.Repo.Repository.IsEmpty = false
+ if err = repo_model.UpdateRepositoryCols(ctx.Repo.Repository, "is_empty"); err != nil {
+ ctx.ServerError("UpdateRepositoryCols", err)
+ return
+ }
+ if err = models.UpdateRepoSize(db.DefaultContext, ctx.Repo.Repository); err != nil {
+ ctx.ServerError("UpdateRepoSize", err)
+ return
+ }
}
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name