summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-01-03 22:47:25 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-01-05 15:17:53 -0300
commit0b07be594e932cd9eb135b82e10931495350cb21 (patch)
tree0d7bed9bba42b62870c058c007c8d7860d6ead3f /app
parent3d162d192ba2a57776de62b553a2a0a9a9245f8a (diff)
downloadgitlab-ce-0b07be594e932cd9eb135b82e10931495350cb21.tar.gz
Move git operations for multi_action into Gitlab::Git
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb67
-rw-r--r--app/services/files/multi_service.rb15
2 files changed, 13 insertions, 69 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 7b8f5794a87..9c879e2006b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -783,34 +783,30 @@ class Repository
end
def create_dir(user, path, **options)
- options[:user] = user
options[:actions] = [{ action: :create_dir, file_path: path }]
- multi_action(**options)
+ multi_action(user, **options)
end
def create_file(user, path, content, **options)
- options[:user] = user
options[:actions] = [{ action: :create, file_path: path, content: content }]
- multi_action(**options)
+ multi_action(user, **options)
end
def update_file(user, path, content, **options)
previous_path = options.delete(:previous_path)
action = previous_path && previous_path != path ? :move : :update
- options[:user] = user
options[:actions] = [{ action: action, file_path: path, previous_path: previous_path, content: content }]
- multi_action(**options)
+ multi_action(user, **options)
end
def delete_file(user, path, **options)
- options[:user] = user
options[:actions] = [{ action: :delete, file_path: path }]
- multi_action(**options)
+ multi_action(user, **options)
end
def with_cache_hooks
@@ -824,59 +820,14 @@ class Repository
result.newrev
end
- def with_branch(user, *args)
- with_cache_hooks do
- Gitlab::Git::OperationService.new(user, raw_repository).with_branch(*args) do |start_commit|
- yield start_commit
- end
- end
- end
-
- # rubocop:disable Metrics/ParameterLists
- def multi_action(
- user:, branch_name:, message:, actions:,
- author_email: nil, author_name: nil,
- start_branch_name: nil, start_project: project)
-
- with_branch(
- user,
- branch_name,
- start_branch_name: start_branch_name,
- start_repository: start_project.repository.raw_repository) do |start_commit|
-
- index = Gitlab::Git::Index.new(raw_repository)
-
- if start_commit
- index.read_tree(start_commit.rugged_commit.tree)
- parents = [start_commit.sha]
- else
- parents = []
- end
+ def multi_action(user, **options)
+ start_project = options.delete(:start_project)
- actions.each do |options|
- index.public_send(options.delete(:action), options) # rubocop:disable GitlabSecurity/PublicSend
- end
-
- options = {
- tree: index.write_tree,
- message: message,
- parents: parents
- }
- options.merge!(get_committer_and_author(user, email: author_email, name: author_name))
-
- create_commit(options)
+ if start_project
+ options[:start_repository] = start_project.repository.raw_repository
end
- end
- # rubocop:enable Metrics/ParameterLists
- def get_committer_and_author(user, email: nil, name: nil)
- committer = user_to_committer(user)
- author = Gitlab::Git.committer_hash(email: email, name: name) || committer
-
- {
- author: author,
- committer: committer
- }
+ with_cache_hooks { raw.multi_action(user, **options) }
end
def can_be_merged?(source_sha, target_branch)
diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb
index 98a3e83c130..a03c59f569d 100644
--- a/app/services/files/multi_service.rb
+++ b/app/services/files/multi_service.rb
@@ -4,7 +4,7 @@ module Files
def create_commit!
repository.multi_action(
- user: current_user,
+ current_user,
message: @commit_message,
branch_name: @branch_name,
actions: params[:actions],
@@ -13,6 +13,8 @@ module Files
start_project: @start_project,
start_branch_name: @start_branch
)
+ rescue ArgumentError => e
+ raise_error(e)
end
private
@@ -20,16 +22,7 @@ module Files
def validate!
super
- params[:actions].each do |action|
- validate_action!(action)
- validate_file_status!(action)
- end
- end
-
- def validate_action!(action)
- unless Gitlab::Git::Index::ACTIONS.include?(action[:action].to_s)
- raise_error("Unknown action '#{action[:action]}'")
- end
+ params[:actions].each { |action| validate_file_status!(action) }
end
def validate_file_status!(action)