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