2014-01-16 18:36:51 +00:00
|
|
|
require_relative "base_service"
|
2013-12-10 12:15:08 +00:00
|
|
|
|
2013-11-05 10:06:52 +00:00
|
|
|
module Files
|
2015-06-02 10:06:40 +00:00
|
|
|
class CreateService < Files::BaseService
|
2015-06-05 13:01:38 +00:00
|
|
|
def commit
|
|
|
|
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch)
|
|
|
|
end
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-06-05 13:01:38 +00:00
|
|
|
def validate
|
|
|
|
super
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-06-05 13:01:38 +00:00
|
|
|
file_name = File.basename(@file_path)
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-03-24 13:55:14 +00:00
|
|
|
unless file_name =~ Gitlab::Regex.file_name_regex
|
2015-06-05 13:01:38 +00:00
|
|
|
raise_error(
|
2014-06-26 07:53:01 +00:00
|
|
|
'Your changes could not be committed, because the file name ' +
|
2015-03-24 13:55:14 +00:00
|
|
|
Gitlab::Regex.file_name_regex_message
|
2014-06-26 07:53:01 +00:00
|
|
|
)
|
2013-11-05 10:06:52 +00:00
|
|
|
end
|
|
|
|
|
2015-06-05 13:01:38 +00:00
|
|
|
unless project.empty_repo?
|
|
|
|
blob = repository.blob_at_branch(@current_branch, @file_path)
|
2015-01-26 21:31:20 +00:00
|
|
|
|
|
|
|
if blob
|
2015-06-05 13:01:38 +00:00
|
|
|
raise_error("Your changes could not be committed, because file with such name exists")
|
2015-06-01 21:43:35 +00:00
|
|
|
end
|
2013-11-05 10:06:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|