Skip to content

Commit 8cc8379

Browse files
committed
When a repository is broken but git repository could be open, then mark it as normal
1 parent 4011e22 commit 8cc8379

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

models/repo/repo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ func (repo *Repository) MarkAsBrokenEmpty() {
320320
repo.IsEmpty = true
321321
}
322322

323+
func (repo *Repository) MarkAsNormal() {
324+
repo.IsEmpty = false
325+
repo.Status = RepositoryReady
326+
}
327+
328+
func MarkBrokenRepoAsNormal(ctx context.Context, repo *Repository) error {
329+
repo.MarkAsNormal()
330+
if _, err := db.GetEngine(ctx).ID(repo.ID).Cols("status", "is_empty").Update(repo); err != nil {
331+
return fmt.Errorf("update repository: %w", err)
332+
}
333+
return nil
334+
}
335+
323336
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
324337
func (repo *Repository) AfterLoad() {
325338
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues

services/context/repo.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func RepoAssignment(ctx *Context) {
567567
ctx.Link == ctx.Repo.RepoLink+"/-/migrate/status"
568568

569569
// Disable everything when the repo is being created
570-
if ctx.Repo.Repository.IsBeingCreated() || ctx.Repo.Repository.IsBroken() {
570+
if ctx.Repo.Repository.IsBeingCreated() {
571571
if !isHomeOrSettings {
572572
ctx.Redirect(ctx.Repo.RepoLink)
573573
}
@@ -595,6 +595,13 @@ func RepoAssignment(ctx *Context) {
595595
return
596596
}
597597

598+
// The repository can be open but marked as broken
599+
if ctx.Repo.Repository.IsBroken() {
600+
if err = repo_model.MarkBrokenRepoAsNormal(ctx, ctx.Repo.Repository); err != nil {
601+
log.Error("MarkBrokenRepoAsNormal: %v", err)
602+
}
603+
}
604+
598605
// Stop at this point when the repo is empty.
599606
if ctx.Repo.Repository.IsEmpty {
600607
return

0 commit comments

Comments
 (0)