diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index 0a67e03..08fd898 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -25,9 +25,8 @@ class TreeController < ProjectResourceController end def update - last_commit = @project.commits(@ref, @path, 1).first.sha - file_editor = Gitlab::FileEditor.new(current_user, @project) - if file_editor.can_edit?(@path, last_commit) + file_editor = Gitlab::FileEditor.new(current_user, @project, @ref) + if file_editor.can_edit?(@path, params[:last_commit]) file_editor.update(@path, params[:content]) redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed" else diff --git a/lib/gitlab/file_editor.rb b/lib/gitlab/file_editor.rb index 2a48cc4..8b39f29 100644 --- a/lib/gitlab/file_editor.rb +++ b/lib/gitlab/file_editor.rb @@ -1,15 +1,17 @@ module Gitlab class FileEditor - attr_accessor :user, :project + attr_accessor :user, :project, :ref - def initialize(user, project) + def initialize(user, project, ref) self.user = user self.project = project + self.ref = ref end def can_edit?(path, last_commit) - true + current_last_commit = @project.commits(ref, path, 1).first.sha + last_commit == current_last_commit end def update(path, content) -- libgit2 0.21.2