Commit 727d229e28012b3469760c69e028192b617b7e15
1 parent
921151d0
Exists in
master
and in
4 other branches
Fix edit files since we use Gitlab::Git::Blob for files
Showing
2 changed files
with
10 additions
and
8 deletions
Show diff stats
app/controllers/edit_tree_controller.rb
| @@ -22,7 +22,7 @@ class EditTreeController < ProjectResourceController | @@ -22,7 +22,7 @@ class EditTreeController < ProjectResourceController | ||
| 22 | ) | 22 | ) |
| 23 | 23 | ||
| 24 | if updated_successfully | 24 | if updated_successfully |
| 25 | - redirect_to project_tree_path(@project, @id), notice: "Your changes have been successfully commited" | 25 | + redirect_to project_blob_path(@project, @id), notice: "Your changes have been successfully commited" |
| 26 | else | 26 | else |
| 27 | flash[:notice] = "Your changes could not be commited, because the file has been changed" | 27 | flash[:notice] = "Your changes could not be commited, because the file has been changed" |
| 28 | render :edit | 28 | render :edit |
| @@ -32,8 +32,10 @@ class EditTreeController < ProjectResourceController | @@ -32,8 +32,10 @@ class EditTreeController < ProjectResourceController | ||
| 32 | private | 32 | private |
| 33 | 33 | ||
| 34 | def edit_requirements | 34 | def edit_requirements |
| 35 | - unless @tree.is_blob? && @tree.text? | ||
| 36 | - redirect_to project_tree_path(@project, @id), notice: "You can only edit text files" | 35 | + @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) |
| 36 | + | ||
| 37 | + unless @blob.exists? && @blob.text? | ||
| 38 | + redirect_to project_blob_path(@project, @id), notice: "You can only edit text files" | ||
| 37 | end | 39 | end |
| 38 | 40 | ||
| 39 | allowed = if project.protected_branch? @ref | 41 | allowed = if project.protected_branch? @ref |
app/views/edit_tree/show.html.haml
| @@ -4,21 +4,21 @@ | @@ -4,21 +4,21 @@ | ||
| 4 | .file_title | 4 | .file_title |
| 5 | %i.icon-file | 5 | %i.icon-file |
| 6 | %span.file_name | 6 | %span.file_name |
| 7 | - = @tree.path | 7 | + = @path |
| 8 | %small | 8 | %small |
| 9 | on | 9 | on |
| 10 | %strong= @ref | 10 | %strong= @ref |
| 11 | %span.options | 11 | %span.options |
| 12 | .btn-group.tree-btn-group | 12 | .btn-group.tree-btn-group |
| 13 | - = link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-tiny btn-cancel", confirm: "Are you sure?" | 13 | + = link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-tiny btn-cancel", confirm: "Are you sure?" |
| 14 | .file_content.code | 14 | .file_content.code |
| 15 | - %pre#editor= @tree.data | 15 | + %pre#editor= @blob.data |
| 16 | 16 | ||
| 17 | .control-group.commit_message-group | 17 | .control-group.commit_message-group |
| 18 | = label_tag 'commit_message', class: "control-label" do | 18 | = label_tag 'commit_message', class: "control-label" do |
| 19 | Commit message | 19 | Commit message |
| 20 | .controls | 20 | .controls |
| 21 | - = text_area_tag 'commit_message', '', placeholder: "Update #{@tree.name}", required: true, rows: 3 | 21 | + = text_area_tag 'commit_message', '', placeholder: "Update #{@blob.name}", required: true, rows: 3 |
| 22 | .form-actions | 22 | .form-actions |
| 23 | = hidden_field_tag 'last_commit', @last_commit | 23 | = hidden_field_tag 'last_commit', @last_commit |
| 24 | = hidden_field_tag 'content', '', id: :file_content | 24 | = hidden_field_tag 'content', '', id: :file_content |
| @@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
| 30 | = link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-cancel", confirm: "Are you sure?" | 30 | = link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-cancel", confirm: "Are you sure?" |
| 31 | 31 | ||
| 32 | :javascript | 32 | :javascript |
| 33 | - var ace_mode = "#{@tree.language.try(:ace_mode)}"; | 33 | + var ace_mode = "#{@blob.language.try(:ace_mode)}"; |
| 34 | var editor = ace.edit("editor"); | 34 | var editor = ace.edit("editor"); |
| 35 | if (ace_mode) { | 35 | if (ace_mode) { |
| 36 | editor.getSession().setMode('ace/mode/' + ace_mode); | 36 | editor.getSession().setMode('ace/mode/' + ace_mode); |