1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-15 23:17:19 +00:00

Refactor some file edit related code (#34744)

Follow up #34350

---------

Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
wxiaoguang
2025-06-18 09:18:07 +08:00
committed by GitHub
parent ecc6685c20
commit 71e4740946
8 changed files with 236 additions and 237 deletions

View File

@@ -288,13 +288,20 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
return
}
operation := "update"
var operation string
if isNewFile {
operation = "create"
} else if !form.Content.Has() && ctx.Repo.TreePath != form.TreePath {
// The form content only has data if file is representable as text, is not too large and not in lfs. If it doesn't
// have data, the only possible operation is a rename
} else if form.Content.Has() {
// The form content only has data if the file is representable as text, is not too large and not in lfs.
operation = "update"
} else if ctx.Repo.TreePath != form.TreePath {
// If it doesn't have data, the only possible operation is a "rename"
operation = "rename"
} else {
// It should never happen, just in case
ctx.Flash.Error(ctx.Tr("error.occurred"))
ctx.HTML(http.StatusOK, tplEditFile)
return
}
if _, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{