@@ -223,17 +223,42 @@ func prepareRecentlyPushedNewBranches(ctx *context.Context) {
223223 }
224224}
225225
226+ func updateContextRepoEmptyAndStatus (ctx * context.Context , empty bool , status repo_model.RepositoryStatus ) {
227+ ctx .Repo .Repository .IsEmpty = empty
228+ if ctx .Repo .Repository .Status == repo_model .RepositoryReady || ctx .Repo .Repository .Status == repo_model .RepositoryBroken {
229+ ctx .Repo .Repository .Status = status // only handle ready and broken status, leave other status as-is
230+ }
231+ if err := repo_model .UpdateRepositoryCols (ctx , ctx .Repo .Repository , "is_empty" , "status" ); err != nil {
232+ ctx .ServerError ("updateContextRepoEmptyAndStatus: UpdateRepositoryCols" , err )
233+ return
234+ }
235+ }
236+
226237func handleRepoEmptyOrBroken (ctx * context.Context ) {
227238 showEmpty := true
228- var err error
229239 if ctx .Repo .GitRepo != nil {
230- showEmpty , err = ctx .Repo .GitRepo .IsEmpty ()
240+ reallyEmpty , err : = ctx .Repo .GitRepo .IsEmpty ()
231241 if err != nil {
232242 log .Error ("GitRepo.IsEmpty: %v" , err )
233243 ctx .Repo .Repository .Status = repo_model .RepositoryBroken
234244 showEmpty = true
235245 ctx .Flash .Error (ctx .Tr ("error.occurred" ), true )
236246 }
247+ if err != nil {
248+ showEmpty = true // the repo is broken
249+ updateContextRepoEmptyAndStatus (ctx , true , repo_model .RepositoryBroken )
250+ } else if reallyEmpty {
251+ showEmpty = true // the repo is really empty
252+ updateContextRepoEmptyAndStatus (ctx , true , repo_model .RepositoryReady )
253+ } else if ctx .Repo .Commit == nil {
254+ showEmpty = true // it is not really empty, but there is no branch
255+ // at the moment, other repo units like "actions" are not able to handle such case,
256+ // so we just mark the repo as empty to prevent from displaying these units.
257+ updateContextRepoEmptyAndStatus (ctx , true , repo_model .RepositoryReady )
258+ } else {
259+ // the repo is actually not empty and has branches, need to update the database later
260+ showEmpty = false
261+ }
237262 }
238263 if showEmpty {
239264 ctx .HTML (http .StatusOK , tplRepoEMPTY )
@@ -246,12 +271,8 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
246271 // and even more: the IsEmpty flag is deeply broken and should be removed with the UI changed to manage to cope with empty repos.
247272 // it's possible for a repository to be non-empty by that flag but still 500
248273 // because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
249- ctx .Repo .Repository .IsEmpty = false
250- if err = repo_model .UpdateRepositoryCols (ctx , ctx .Repo .Repository , "is_empty" ); err != nil {
251- ctx .ServerError ("UpdateRepositoryCols" , err )
252- return
253- }
254- if err = repo_module .UpdateRepoSize (ctx , ctx .Repo .Repository ); err != nil {
274+ updateContextRepoEmptyAndStatus (ctx , false , repo_model .RepositoryReady )
275+ if err := repo_module .UpdateRepoSize (ctx , ctx .Repo .Repository ); err != nil {
255276 ctx .ServerError ("UpdateRepoSize" , err )
256277 return
257278 }
0 commit comments