debian-mirror-gitlab/app/services/files/create_service.rb

33 lines
849 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require_relative "base_service"
module Files
2015-09-25 12:07:36 +05:30
class CreateService < Files::BaseService
def commit
2015-10-24 18:46:33 +05:30
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch, false)
2015-09-25 12:07:36 +05:30
end
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
def validate
super
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
file_name = File.basename(@file_path)
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
unless file_name =~ Gitlab::Regex.file_name_regex
2015-09-25 12:07:36 +05:30
raise_error(
2014-09-02 18:07:02 +05:30
'Your changes could not be committed, because the file name ' +
2015-04-26 12:48:37 +05:30
Gitlab::Regex.file_name_regex_message
2014-09-02 18:07:02 +05:30
)
end
2015-09-25 12:07:36 +05:30
unless project.empty_repo?
@file_path.slice!(0) if @file_path.start_with?('/')
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
blob = repository.blob_at_branch(@current_branch, @file_path)
2015-04-26 12:48:37 +05:30
if blob
2015-09-25 12:07:36 +05:30
raise_error("Your changes could not be committed because a file with the same name already exists")
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
end
end