Skip to content

Commit 5dc082a

Browse files
committed
Make LFS file paths editable
1 parent 96bbf81 commit 5dc082a

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

routers/web/repo/editor.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,16 @@ func editFile(ctx *context.Context, isNewFile bool) {
165165
ctx.Data["FileSize"] = blob.Size()
166166

167167
// Only some file types are editable online as text.
168-
ctx.Data["IsFileEditable"] = fInfo.isTextFile && !fInfo.isLFSFile
168+
ctx.Data["IsFileEditable"] = fInfo.isTextFile && !fInfo.isLFSFile && blob.Size() < setting.UI.MaxDisplayFileSize
169+
170+
if fInfo.isLFSFile {
171+
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
172+
} else if !fInfo.isTextFile {
173+
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.binary_file_not_editable")
174+
}
169175

170176
if blob.Size() >= setting.UI.MaxDisplayFileSize {
171-
ctx.Data["IsFileTooLarge"] = true
177+
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.file_too_large_not_editable")
172178
} else {
173179
d, _ := io.ReadAll(dataRc)
174180

routers/web/repo/view_file.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,23 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
285285
}
286286
}
287287

288-
if fInfo.isLFSFile {
289-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
290-
} else {
291-
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
292-
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
293-
ctx.Data["CanEditFile"] = false
294-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
295-
} else {
296-
ctx.Data["CanEditFile"] = true
297-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
298-
}
299-
} else if !ctx.Repo.RefFullName.IsBranch() {
300-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
301-
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
302-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
303-
}
304-
}
305-
306288
if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {
307289
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
290+
ctx.Data["CanEditFile"] = false
291+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
308292
ctx.Data["CanDeleteFile"] = false
309293
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
310294
} else {
295+
ctx.Data["CanEditFile"] = true
296+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
311297
ctx.Data["CanDeleteFile"] = true
312298
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
313299
}
314300
} else if !ctx.Repo.RefFullName.IsBranch() {
301+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
315302
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
316303
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
304+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
317305
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
318306
}
319307
}

templates/repo/editor/edit.tmpl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,10 @@
5454
</div>
5555
</div>
5656
</div>
57-
{{else if .IsFileTooLarge}}
58-
<div class="field">
59-
<div class="ui segment tw-text-center">
60-
<h4 class="tw-font-semibold tw-mb-2">{{ctx.Locale.Tr "repo.editor.file_too_large_not_editable"}}</h4>
61-
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
62-
</div>
63-
</div>
6457
{{else}}
6558
<div class="field">
6659
<div class="ui segment tw-text-center">
67-
<h4 class="tw-font-semibold tw-mb-2">{{ctx.Locale.Tr "repo.editor.binary_file_not_editable"}}</h4>
60+
<h4 class="tw-font-semibold tw-mb-2">{{.NotEditableReason}}</h4>
6861
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
6962
</div>
7063
</div>

0 commit comments

Comments
 (0)