Skip to content

Commit b337dda

Browse files
committed
fix
1 parent 2b064b8 commit b337dda

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

models/repo/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func (repo *Repository) IsBroken() bool {
279279
}
280280

281281
// MarkAsBrokenEmpty marks the repo as broken and empty
282+
// FIXME: the status "broken" and "is_empty" were abused,
283+
// The code always set them together, no way to distinguish whether a repo is really "empty" or "broken"
282284
func (repo *Repository) MarkAsBrokenEmpty() {
283285
repo.Status = RepositoryBroken
284286
repo.IsEmpty = true

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ create_new_repo_command = Creating a new repository on the command line
12351235
push_exist_repo = Pushing an existing repository from the command line
12361236
empty_message = This repository does not contain any content.
12371237
broken_message = The Git data underlying this repository cannot be read. Contact the administrator of this instance or delete this repository.
1238+
no_branch = This repository doesn’t have any branches.
12381239
12391240
code = Code
12401241
code.desc = Access source code, files, commits and branches.

routers/web/repo/view_home.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,28 @@ func prepareRecentlyPushedNewBranches(ctx *context.Context) {
225225

226226
func handleRepoEmptyOrBroken(ctx *context.Context) {
227227
showEmpty := true
228-
var err error
229228
if ctx.Repo.GitRepo != nil {
230-
showEmpty, err = ctx.Repo.GitRepo.IsEmpty()
229+
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
231230
if err != nil {
232231
log.Error("GitRepo.IsEmpty: %v", err)
233232
ctx.Repo.Repository.Status = repo_model.RepositoryBroken
234233
showEmpty = true
235234
ctx.Flash.Error(ctx.Tr("error.occurred"), true)
236235
}
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+
}
237250
}
238251
if showEmpty {
239252
ctx.HTML(http.StatusOK, tplRepoEMPTY)
@@ -247,11 +260,14 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
247260
// it's possible for a repository to be non-empty by that flag but still 500
248261
// because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
249262
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 {
251267
ctx.ServerError("UpdateRepositoryCols", err)
252268
return
253269
}
254-
if err = repo_module.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil {
270+
if err := repo_module.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil {
255271
ctx.ServerError("UpdateRepoSize", err)
256272
return
257273
}

services/context/repo.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,8 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
897897
refName = brs[0].Name
898898
} else if len(brs) == 0 {
899899
log.Error("No branches in non-empty repository %s", ctx.Repo.GitRepo.Path)
900-
ctx.Repo.Repository.MarkAsBrokenEmpty()
901900
} else {
902901
log.Error("GetBranches error: %v", err)
903-
ctx.Repo.Repository.MarkAsBrokenEmpty()
904902
}
905903
}
906904
ctx.Repo.RefName = refName
@@ -911,7 +909,6 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
911909
} else if strings.Contains(err.Error(), "fatal: not a git repository") || strings.Contains(err.Error(), "object does not exist") {
912910
// if the repository is broken, we can continue to the handler code, to show "Settings -> Delete Repository" for end users
913911
log.Error("GetBranchCommit: %v", err)
914-
ctx.Repo.Repository.MarkAsBrokenEmpty()
915912
} else {
916913
ctx.ServerError("GetBranchCommit", err)
917914
return

templates/repo/empty.tmpl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
{{end}}
1515
</div>
1616
{{end}}
17+
1718
{{if .Repository.IsBroken}}
18-
<div class="ui segment center">
19-
{{ctx.Locale.Tr "repo.broken_message"}}
20-
</div>
19+
<div class="ui segment center">{{ctx.Locale.Tr "repo.broken_message"}}</div>
20+
{{else if .Repository.IsEmpty}}
21+
<div class="ui segment center">{{ctx.Locale.Tr "repo.no_branch"}}</div>
2122
{{else if .CanWriteCode}}
22-
<h4 class="ui top attached header">
23-
{{ctx.Locale.Tr "repo.quick_guide"}}
24-
</h4>
23+
<h4 class="ui top attached header">{{ctx.Locale.Tr "repo.quick_guide"}}</h4>
2524
<div class="ui attached guide table segment empty-repo-guide">
2625
<div class="item">
2726
<h3>{{ctx.Locale.Tr "repo.clone_this_repo"}} <small>{{ctx.Locale.Tr "repo.clone_helper" "http://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository"}}</small></h3>
@@ -66,12 +65,10 @@ git push -u origin {{.Repository.DefaultBranch}}</code></pre>
6665
</div>
6766
</div>
6867
{{end}}
69-
{{else}}
70-
<div class="ui segment center">
71-
{{ctx.Locale.Tr "repo.empty_message"}}
72-
</div>
73-
{{end}}
74-
</div>
68+
</div>
69+
{{else}}
70+
<div class="ui segment center">{{ctx.Locale.Tr "repo.empty_message"}}</div>
71+
{{end}}
7572
</div>
7673
</div>
7774
</div>

templates/repo/header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
</a>
163163
{{end}}
164164

165-
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
165+
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions) (not .IsEmptyRepo)}}
166166
<a class="{{if .PageIsActions}}active {{end}}item" href="{{.RepoLink}}/actions">
167167
{{svg "octicon-play"}} {{ctx.Locale.Tr "actions.actions"}}
168168
{{if .Repository.NumOpenActionRuns}}

0 commit comments

Comments
 (0)