@@ -145,10 +145,6 @@ func editFile(ctx *context.Context, isNewFile bool) {
145145 }
146146
147147 blob := entry .Blob ()
148- if blob .Size () >= setting .UI .MaxDisplayFileSize {
149- ctx .NotFound (err )
150- return
151- }
152148
153149 buf , dataRc , fInfo , err := getFileReader (ctx , ctx .Repo .Repository .ID , blob )
154150 if err != nil {
@@ -162,22 +158,37 @@ func editFile(ctx *context.Context, isNewFile bool) {
162158
163159 defer dataRc .Close ()
164160
165- ctx .Data ["FileSize" ] = blob .Size ()
166-
167- // Only some file types are editable online as text.
168- if ! fInfo .st .IsRepresentableAsText () || fInfo .isLFSFile {
169- ctx .NotFound (nil )
170- return
161+ if fInfo .isLFSFile {
162+ lfsLock , err := git_model .GetTreePathLock (ctx , ctx .Repo .Repository .ID , ctx .Repo .TreePath )
163+ if err != nil {
164+ ctx .ServerError ("GetTreePathLock" , err )
165+ return
166+ }
167+ if lfsLock != nil && lfsLock .OwnerID != ctx .Doer .ID {
168+ ctx .NotFound (nil )
169+ return
170+ }
171171 }
172172
173- d , _ := io . ReadAll ( dataRc )
173+ ctx . Data [ "FileSize" ] = fInfo . fileSize
174174
175- buf = append (buf , d ... )
176- if content , err := charset .ToUTF8 (buf , charset.ConvertOpts {KeepBOM : true }); err != nil {
177- log .Error ("ToUTF8: %v" , err )
178- ctx .Data ["FileContent" ] = string (buf )
175+ // Only some file types are editable online as text.
176+ if fInfo .isLFSFile {
177+ ctx .Data ["NotEditableReason" ] = ctx .Tr ("repo.editor.cannot_edit_lfs_files" )
178+ } else if ! fInfo .st .IsRepresentableAsText () {
179+ ctx .Data ["NotEditableReason" ] = ctx .Tr ("repo.editor.cannot_edit_non_text_files" )
180+ } else if fInfo .fileSize >= setting .UI .MaxDisplayFileSize {
181+ ctx .Data ["NotEditableReason" ] = ctx .Tr ("repo.editor.cannot_edit_too_large_file" )
179182 } else {
180- ctx .Data ["FileContent" ] = content
183+ d , _ := io .ReadAll (dataRc )
184+
185+ buf = append (buf , d ... )
186+ if content , err := charset .ToUTF8 (buf , charset.ConvertOpts {KeepBOM : true }); err != nil {
187+ log .Error ("ToUTF8: %v" , err )
188+ ctx .Data ["FileContent" ] = string (buf )
189+ } else {
190+ ctx .Data ["FileContent" ] = content
191+ }
181192 }
182193 } else {
183194 // Append filename from query, or empty string to allow username the new file.
@@ -280,6 +291,10 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
280291 operation := "update"
281292 if isNewFile {
282293 operation = "create"
294+ } else if ! form .Content .Has () && ctx .Repo .TreePath != form .TreePath {
295+ // The form content only has data if file is representable as text, is not too large and not in lfs. If it doesn't
296+ // have data, the only possible operation is a rename
297+ operation = "rename"
283298 }
284299
285300 if _ , err := files_service .ChangeRepoFiles (ctx , ctx .Repo .Repository , ctx .Doer , & files_service.ChangeRepoFilesOptions {
@@ -292,7 +307,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
292307 Operation : operation ,
293308 FromTreePath : ctx .Repo .TreePath ,
294309 TreePath : form .TreePath ,
295- ContentReader : strings .NewReader (strings .ReplaceAll (form .Content , "\r " , "" )),
310+ ContentReader : strings .NewReader (strings .ReplaceAll (form .Content . Value () , "\r " , "" )),
296311 },
297312 },
298313 Signoff : form .Signoff ,
0 commit comments