Commit 727d229e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix edit files since we use Gitlab::Git::Blob for files

parent 921151d0
...@@ -22,7 +22,7 @@ class EditTreeController < ProjectResourceController ...@@ -22,7 +22,7 @@ class EditTreeController < ProjectResourceController
) )
if updated_successfully if updated_successfully
redirect_to project_tree_path(@project, @id), notice: "Your changes have been successfully commited" redirect_to project_blob_path(@project, @id), notice: "Your changes have been successfully commited"
else else
flash[:notice] = "Your changes could not be commited, because the file has been changed" flash[:notice] = "Your changes could not be commited, because the file has been changed"
render :edit render :edit
...@@ -32,8 +32,10 @@ class EditTreeController < ProjectResourceController ...@@ -32,8 +32,10 @@ class EditTreeController < ProjectResourceController
private private
def edit_requirements def edit_requirements
unless @tree.is_blob? && @tree.text? @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
redirect_to project_tree_path(@project, @id), notice: "You can only edit text files"
unless @blob.exists? && @blob.text?
redirect_to project_blob_path(@project, @id), notice: "You can only edit text files"
end end
allowed = if project.protected_branch? @ref allowed = if project.protected_branch? @ref
......
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
.file_title .file_title
%i.icon-file %i.icon-file
%span.file_name %span.file_name
= @tree.path = @path
%small %small
on on
%strong= @ref %strong= @ref
%span.options %span.options
.btn-group.tree-btn-group .btn-group.tree-btn-group
= link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-tiny btn-cancel", confirm: "Are you sure?" = link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-tiny btn-cancel", confirm: "Are you sure?"
.file_content.code .file_content.code
%pre#editor= @tree.data %pre#editor= @blob.data
.control-group.commit_message-group .control-group.commit_message-group
= label_tag 'commit_message', class: "control-label" do = label_tag 'commit_message', class: "control-label" do
Commit message Commit message
.controls .controls
= text_area_tag 'commit_message', '', placeholder: "Update #{@tree.name}", required: true, rows: 3 = text_area_tag 'commit_message', '', placeholder: "Update #{@blob.name}", required: true, rows: 3
.form-actions .form-actions
= hidden_field_tag 'last_commit', @last_commit = hidden_field_tag 'last_commit', @last_commit
= hidden_field_tag 'content', '', id: :file_content = hidden_field_tag 'content', '', id: :file_content
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
= link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-cancel", confirm: "Are you sure?" = link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-cancel", confirm: "Are you sure?"
:javascript :javascript
var ace_mode = "#{@tree.language.try(:ace_mode)}"; var ace_mode = "#{@blob.language.try(:ace_mode)}";
var editor = ace.edit("editor"); var editor = ace.edit("editor");
if (ace_mode) { if (ace_mode) {
editor.getSession().setMode('ace/mode/' + ace_mode); editor.getSession().setMode('ace/mode/' + ace_mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment