Commit 727d229e28012b3469760c69e028192b617b7e15

Authored by Dmitriy Zaporozhets
1 parent 921151d0

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

app/controllers/edit_tree_controller.rb
... ... @@ -22,7 +22,7 @@ class EditTreeController < ProjectResourceController
22 22 )
23 23  
24 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 26 else
27 27 flash[:notice] = "Your changes could not be commited, because the file has been changed"
28 28 render :edit
... ... @@ -32,8 +32,10 @@ class EditTreeController < ProjectResourceController
32 32 private
33 33  
34 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 39 end
38 40  
39 41 allowed = if project.protected_branch? @ref
... ...
app/views/edit_tree/show.html.haml
... ... @@ -4,21 +4,21 @@
4 4 .file_title
5 5 %i.icon-file
6 6 %span.file_name
7   - = @tree.path
  7 + = @path
8 8 %small
9 9 on
10 10 %strong= @ref
11 11 %span.options
12 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 14 .file_content.code
15   - %pre#editor= @tree.data
  15 + %pre#editor= @blob.data
16 16  
17 17 .control-group.commit_message-group
18 18 = label_tag 'commit_message', class: "control-label" do
19 19 Commit message
20 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 22 .form-actions
23 23 = hidden_field_tag 'last_commit', @last_commit
24 24 = hidden_field_tag 'content', '', id: :file_content
... ... @@ -30,7 +30,7 @@
30 30 = link_to "Cancel", project_tree_path(@project, @id), class: "btn btn-cancel", confirm: "Are you sure?"
31 31  
32 32 :javascript
33   - var ace_mode = "#{@tree.language.try(:ace_mode)}";
  33 + var ace_mode = "#{@blob.language.try(:ace_mode)}";
34 34 var editor = ace.edit("editor");
35 35 if (ace_mode) {
36 36 editor.getSession().setMode('ace/mode/' + ace_mode);
... ...