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-08-11 12:33:31 +00:00
|
|
|
class CreateService < Files::BaseService
|
|
|
|
def commit
|
2015-09-17 05:45:22 +00:00
|
|
|
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch, false)
|
2015-08-11 12:33:31 +00:00
|
|
|
end
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-08-11 12:33:31 +00:00
|
|
|
def validate
|
|
|
|
super
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-10-19 21:52:46 +00:00
|
|
|
if @file_path =~ Gitlab::Regex.directory_traversal_regex
|
|
|
|
raise_error(
|
|
|
|
'Your changes could not be committed, because the file name ' +
|
|
|
|
Gitlab::Regex.directory_traversal_regex_message
|
|
|
|
)
|
|
|
|
end
|
2013-11-05 10:06:52 +00:00
|
|
|
|
2015-10-19 21:52:46 +00:00
|
|
|
unless @file_path =~ Gitlab::Regex.file_path_regex
|
2015-08-11 12:33:31 +00:00
|
|
|
raise_error(
|
2014-06-26 07:53:01 +00:00
|
|
|
'Your changes could not be committed, because the file name ' +
|
2015-10-19 21:52:46 +00:00
|
|
|
Gitlab::Regex.file_path_regex_message
|
2014-06-26 07:53:01 +00:00
|
|
|
)
|
2013-11-05 10:06:52 +00:00
|
|
|
end
|
|
|
|
|
2015-08-11 12:33:31 +00:00
|
|
|
unless project.empty_repo?
|
2015-09-10 14:18:40 +00:00
|
|
|
@file_path.slice!(0) if @file_path.start_with?('/')
|
|
|
|
|
2015-12-18 09:03:34 +00:00
|
|
|
blob = repository.blob_at_branch(@source_branch, @file_path)
|
2015-01-26 21:31:20 +00:00
|
|
|
|
|
|
|
if blob
|
2016-07-06 13:26:59 +00:00
|
|
|
raise_error('Your changes could not be committed because a file with the same name already exists')
|
2015-08-11 09:49:09 +00:00
|
|
|
end
|
|
|
|
end
|
2013-11-05 10:06:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|