gitlab-org--gitlab-foss/app/services/files/multi_service.rb

39 lines
983 B
Ruby
Raw Normal View History

module Files
class MultiService < Files::BaseService
UPDATE_FILE_ACTIONS = %w(update move delete).freeze
2017-04-19 20:37:44 -04:00
def create_commit!
repository.multi_action(
current_user,
message: @commit_message,
2017-04-19 20:37:44 -04:00
branch_name: @branch_name,
actions: params[:actions],
author_email: @author_email,
author_name: @author_name,
start_project: @start_project,
start_branch_name: @start_branch
)
rescue ArgumentError => e
raise_error(e)
end
private
2017-04-19 20:37:44 -04:00
def validate!
super
2017-02-24 15:11:10 -05:00
params[:actions].each { |action| validate_file_status!(action) }
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