@@ -225,15 +225,28 @@ func prepareRecentlyPushedNewBranches(ctx *context.Context) {
225
225
226
226
func handleRepoEmptyOrBroken (ctx * context.Context ) {
227
227
showEmpty := true
228
- var err error
229
228
if ctx .Repo .GitRepo != nil {
230
- showEmpty , err = ctx .Repo .GitRepo .IsEmpty ()
229
+ reallyEmpty , err : = ctx .Repo .GitRepo .IsEmpty ()
231
230
if err != nil {
232
231
log .Error ("GitRepo.IsEmpty: %v" , err )
233
232
ctx .Repo .Repository .Status = repo_model .RepositoryBroken
234
233
showEmpty = true
235
234
ctx .Flash .Error (ctx .Tr ("error.occurred" ), true )
236
235
}
236
+ if reallyEmpty {
237
+ showEmpty = true
238
+ } else if ctx .Repo .Commit == nil {
239
+ showEmpty = true // it is not really empty, but there is no branch
240
+ updateRepo := & repo_model.Repository {ID : ctx .Repo .Repository .ID , IsEmpty : true , Status : repo_model .RepositoryReady }
241
+ // at the moment, other repo units like "actions" are not able to handle such case,
242
+ // so we just mark the repo as empty to prevent from displaying these units.
243
+ if err = repo_model .UpdateRepositoryCols (ctx , updateRepo , "is_empty" , "status" ); err != nil {
244
+ ctx .ServerError ("UpdateRepositoryCols" , err )
245
+ return
246
+ }
247
+ } else {
248
+ showEmpty = false // the repo is actually not empty and has branches, need to update the database
249
+ }
237
250
}
238
251
if showEmpty {
239
252
ctx .HTML (http .StatusOK , tplRepoEMPTY )
@@ -247,11 +260,14 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
247
260
// it's possible for a repository to be non-empty by that flag but still 500
248
261
// because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
249
262
ctx .Repo .Repository .IsEmpty = false
250
- if err = repo_model .UpdateRepositoryCols (ctx , ctx .Repo .Repository , "is_empty" ); err != nil {
263
+ if ctx .Repo .Repository .Status == repo_model .RepositoryBroken {
264
+ ctx .Repo .Repository .Status = repo_model .RepositoryReady
265
+ }
266
+ if err := repo_model .UpdateRepositoryCols (ctx , ctx .Repo .Repository , "is_empty" , "status" ); err != nil {
251
267
ctx .ServerError ("UpdateRepositoryCols" , err )
252
268
return
253
269
}
254
- if err = repo_module .UpdateRepoSize (ctx , ctx .Repo .Repository ); err != nil {
270
+ if err : = repo_module .UpdateRepoSize (ctx , ctx .Repo .Repository ); err != nil {
255
271
ctx .ServerError ("UpdateRepoSize" , err )
256
272
return
257
273
}
0 commit comments