Skip to content

Commit de4f10b

Browse files
lukbukkitlafriks
authored andcommitted
Allow committing / adding empty files using the web ui (#8420) (#8532)
* Allow committing / adding empty files from the web ui (#8420) Signed-off-by: LukBukkit <[email protected]> * Add a modal to confirm the commit of an empty file Signed-off-by: LukBukkit <[email protected]>
1 parent d4cd4ed commit de4f10b

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

modules/auth/repo_form.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) bindin
557557
// EditRepoFileForm form for changing repository file
558558
type EditRepoFileForm struct {
559559
TreePath string `binding:"Required;MaxSize(500)"`
560-
Content string `binding:"Required"`
560+
Content string
561561
CommitSummary string `binding:"MaxSize(100)"`
562562
CommitMessage string
563563
CommitChoice string `binding:"Required;MaxSize(50)"`

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ editor.file_editing_no_longer_exists = The file being edited, '%s', no longer ex
726726
editor.file_deleting_no_longer_exists = The file being deleted, '%s', no longer exists in this repository.
727727
editor.file_changed_while_editing = The file contents have changed since you started editing. <a target="_blank" rel="noopener noreferrer" href="%s">Click here</a> to see them or <strong>Commit Changes again</strong> to overwrite them.
728728
editor.file_already_exists = A file named '%s' already exists in this repository.
729+
editor.commit_empty_file_header = Commit an empty file
730+
editor.commit_empty_file_text = The file you're about commit is empty. Proceed?
729731
editor.no_changes_to_show = There are no changes to show.
730732
editor.fail_to_update_file = Failed to update/create file '%s' with error: %v
731733
editor.add_subdir = Add a directory…

public/js/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function initRepoStatusChecker() {
262262
location.reload();
263263
return
264264
}
265-
265+
266266
setTimeout(function () {
267267
initRepoStatusChecker()
268268
}, 2000);
@@ -1571,6 +1571,18 @@ function initEditor() {
15711571
codeMirrorEditor.setOption("tabSize", editorconfig.tab_width || 4);
15721572
});
15731573
}).trigger('keyup');
1574+
1575+
$('#commit-button').click(function (event) {
1576+
// A modal which asks if an empty file should be committed
1577+
if ($editArea.val().length === 0) {
1578+
$('#edit-empty-content-modal').modal({
1579+
onApprove: function () {
1580+
$('.edit.form').submit();
1581+
}
1582+
}).modal('show');
1583+
event.preventDefault();
1584+
}
1585+
});
15741586
}
15751587

15761588
function initOrganization() {

templates/repo/editor/edit.tmpl

+23-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
data-url="{{.Repository.APIURL}}/markdown"
4040
data-context="{{.RepoLink}}"
4141
data-markdown-file-exts="{{.MarkdownFileExts}}"
42-
data-line-wrap-extensions="{{.LineWrapExtensions}}"
43-
required>
42+
data-line-wrap-extensions="{{.LineWrapExtensions}}">
4443
{{.FileContent}}</textarea>
4544
</div>
4645
<div class="ui bottom attached tab segment markdown" data-tab="preview">
@@ -53,5 +52,27 @@
5352
{{template "repo/editor/commit_form" .}}
5453
</form>
5554
</div>
55+
56+
57+
<div class="ui small basic modal" id="edit-empty-content-modal">
58+
<div class="ui icon header">
59+
<i class="file icon"></i>
60+
{{.i18n.Tr "repo.editor.commit_empty_file_header"}}
61+
</div>
62+
<div class="center content">
63+
<p>{{.i18n.Tr "repo.editor.commit_empty_file_text"}}</p>
64+
</div>
65+
<div class="actions">
66+
<div class="ui red basic cancel inverted button">
67+
<i class="remove icon"></i>
68+
{{.i18n.Tr "repo.editor.cancel"}}
69+
</div>
70+
<div class="ui green basic ok inverted button">
71+
<i class="save icon"></i>
72+
{{.i18n.Tr "repo.editor.commit_changes"}}
73+
</div>
74+
</div>
75+
</div>
76+
5677
</div>
5778
{{template "base/footer" .}}

0 commit comments

Comments
 (0)