summaryrefslogtreecommitdiff
path: root/app/services/files/multi_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/files/multi_service.rb')
-rw-r--r--app/services/files/multi_service.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb
index bfacc462847..98a3e83c130 100644
--- a/app/services/files/multi_service.rb
+++ b/app/services/files/multi_service.rb
@@ -1,5 +1,7 @@
module Files
class MultiService < Files::BaseService
+ UPDATE_FILE_ACTIONS = %w(update move delete).freeze
+
def create_commit!
repository.multi_action(
user: current_user,
@@ -20,6 +22,7 @@ module Files
params[:actions].each do |action|
validate_action!(action)
+ validate_file_status!(action)
end
end
@@ -28,5 +31,15 @@ module Files
raise_error("Unknown action '#{action[:action]}'")
end
end
+
+ def validate_file_status!(action)
+ return unless UPDATE_FILE_ACTIONS.include?(action[:action])
+
+ file_path = action[:previous_path] || action[:file_path]
+
+ if file_has_changed?(file_path, action[:last_commit_id])
+ raise_error("The file has changed since you started editing it: #{file_path}")
+ end
+ end
end
end