Skip to content

Commit e78c6c4

Browse files
committed
markRepositoryAsNonEmpty
1 parent 693e600 commit e78c6c4

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

routers/web/repo/editor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
402402
}
403403
}
404404

405-
updateEditRepositoryIsEmpty(ctx, editRepo)
405+
markRepositoryAsNonEmpty(ctx, editRepo) // a file has been edited, so the repository is no longer empty
406406

407407
redirectForCommitChoice(ctx, editRepo, form.CommitChoice, branchName, form.TreePath)
408408
}
@@ -829,7 +829,7 @@ func UploadFilePost(ctx *context.Context) {
829829
return
830830
}
831831

832-
updateEditRepositoryIsEmpty(ctx, editRepo)
832+
markRepositoryAsNonEmpty(ctx, editRepo) // a file has been uploaded, so the repository is no longer empty
833833

834834
redirectForCommitChoice(ctx, editRepo, form.CommitChoice, branchName, form.TreePath)
835835
}

routers/web/repo/fork_to_edit.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
repo_model "code.gitea.io/gitea/models/repo"
1515
"code.gitea.io/gitea/models/unit"
1616
"code.gitea.io/gitea/modules/git"
17-
"code.gitea.io/gitea/modules/gitrepo"
1817
"code.gitea.io/gitea/modules/log"
1918
repo_module "code.gitea.io/gitea/modules/repository"
2019
"code.gitea.io/gitea/modules/templates"
@@ -160,22 +159,12 @@ func pushToEditRepositoryOrError(ctx *context.Context, editRepo *repo_model.Repo
160159
return branchName, nil
161160
}
162161

163-
// updateEditRepositoryIsEmpty updates the the edit repository to mark it as no longer empty
164-
func updateEditRepositoryIsEmpty(ctx *context.Context, editRepo *repo_model.Repository) {
162+
// markRepositoryAsNonEmpty marks the repository as no longer empty
163+
func markRepositoryAsNonEmpty(ctx *context.Context, editRepo *repo_model.Repository) {
165164
if !editRepo.IsEmpty {
166165
return
167166
}
168-
169-
editGitRepo, err := gitrepo.OpenRepository(ctx, editRepo)
170-
if err != nil {
171-
log.Error("gitrepo.OpenRepository: %v", err)
172-
return
173-
}
174-
defer editGitRepo.Close()
175-
176-
if isEmpty, err := editGitRepo.IsEmpty(); err == nil && !isEmpty {
177-
_ = repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: editRepo.ID, IsEmpty: false}, "is_empty")
178-
}
167+
_ = repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: editRepo.ID, IsEmpty: false}, "is_empty")
179168
}
180169

181170
func forkToEditFileCommon(ctx *context.Context, editOperation, treePath string, notEditableMessage any) {

0 commit comments

Comments
 (0)