diff options
Diffstat (limited to 'routers/web/repo/editor.go')
-rw-r--r-- | routers/web/repo/editor.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 62bf8b182f..1a090c9437 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -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{ @@ -810,7 +817,7 @@ func cleanUploadFileName(name string) string { // Rebase the filename name = util.PathJoinRel(name) // Git disallows any filenames to have a .git directory in them. - for _, part := range strings.Split(name, "/") { + for part := range strings.SplitSeq(name, "/") { if strings.ToLower(part) == ".git" { return "" } |