Commit a05a2949 authored by Robert Speicher's avatar Robert Speicher

Add plumbing for dry-run cherry-pick and revert

This passes the flag from ChangeService to Repository, which passes it
to Gitlab::Git, then to the Gitaly client, then to Gitaly. It defaults
to `false` at all points, maintaining existing behavior.
parent 8ccd460d
...@@ -852,7 +852,7 @@ class Repository ...@@ -852,7 +852,7 @@ class Repository
def revert( def revert(
user, commit, branch_name, message, user, commit, branch_name, message,
start_branch_name: nil, start_project: project) start_branch_name: nil, start_project: project, dry_run: false)
with_cache_hooks do with_cache_hooks do
raw_repository.revert( raw_repository.revert(
...@@ -861,14 +861,15 @@ class Repository ...@@ -861,14 +861,15 @@ class Repository
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_project.repository.raw_repository start_repository: start_project.repository.raw_repository,
dry_run: dry_run
) )
end end
end end
def cherry_pick( def cherry_pick(
user, commit, branch_name, message, user, commit, branch_name, message,
start_branch_name: nil, start_project: project) start_branch_name: nil, start_project: project, dry_run: false)
with_cache_hooks do with_cache_hooks do
raw_repository.cherry_pick( raw_repository.cherry_pick(
...@@ -877,7 +878,8 @@ class Repository ...@@ -877,7 +878,8 @@ class Repository
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_project.repository.raw_repository start_repository: start_project.repository.raw_repository,
dry_run: dry_run
) )
end end
end end
......
...@@ -22,7 +22,9 @@ module Commits ...@@ -22,7 +22,9 @@ module Commits
@branch_name, @branch_name,
message, message,
start_project: @start_project, start_project: @start_project,
start_branch_name: @start_branch) start_branch_name: @start_branch,
dry_run: @dry_run
)
rescue Gitlab::Git::Repository::CreateTreeError => ex rescue Gitlab::Git::Repository::CreateTreeError => ex
act = action.to_s.dasherize act = action.to_s.dasherize
type = @commit.change_type_title(current_user) type = @commit.change_type_title(current_user)
......
...@@ -21,6 +21,7 @@ module Commits ...@@ -21,6 +21,7 @@ module Commits
@start_sha = params[:start_sha] @start_sha = params[:start_sha]
@branch_name = params[:branch_name] @branch_name = params[:branch_name]
@force = params[:force] || false @force = params[:force] || false
@dry_run = params[:dry_run] || false
end end
def execute def execute
......
...@@ -598,14 +598,15 @@ module Gitlab ...@@ -598,14 +598,15 @@ module Gitlab
end end
end end
def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
args = { args = {
user: user, user: user,
commit: commit, commit: commit,
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_repository start_repository: start_repository,
dry_run: dry_run
} }
wrapped_gitaly_errors do wrapped_gitaly_errors do
...@@ -613,14 +614,15 @@ module Gitlab ...@@ -613,14 +614,15 @@ module Gitlab
end end
end end
def cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
args = { args = {
user: user, user: user,
commit: commit, commit: commit,
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_repository start_repository: start_repository,
dry_run: dry_run
} }
wrapped_gitaly_errors do wrapped_gitaly_errors do
......
...@@ -187,24 +187,26 @@ module Gitlab ...@@ -187,24 +187,26 @@ module Gitlab
raise Gitlab::Git::CommitError, e raise Gitlab::Git::CommitError, e
end end
def user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
call_cherry_pick_or_revert(:cherry_pick, call_cherry_pick_or_revert(:cherry_pick,
user: user, user: user,
commit: commit, commit: commit,
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_repository) start_repository: start_repository,
dry_run: dry_run)
end end
def user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
call_cherry_pick_or_revert(:revert, call_cherry_pick_or_revert(:revert,
user: user, user: user,
commit: commit, commit: commit,
branch_name: branch_name, branch_name: branch_name,
message: message, message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_repository) start_repository: start_repository,
dry_run: dry_run)
end end
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: []) def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: [])
...@@ -390,7 +392,7 @@ module Gitlab ...@@ -390,7 +392,7 @@ module Gitlab
response response
end end
def call_cherry_pick_or_revert(rpc, user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def call_cherry_pick_or_revert(rpc, user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run:)
request_class = "Gitaly::User#{rpc.to_s.camelcase}Request".constantize request_class = "Gitaly::User#{rpc.to_s.camelcase}Request".constantize
request = request_class.new( request = request_class.new(
...@@ -400,7 +402,8 @@ module Gitlab ...@@ -400,7 +402,8 @@ module Gitlab
branch_name: encode_binary(branch_name), branch_name: encode_binary(branch_name),
message: encode_binary(message), message: encode_binary(message),
start_branch_name: encode_binary(start_branch_name.to_s), start_branch_name: encode_binary(start_branch_name.to_s),
start_repository: start_repository.gitaly_repository start_repository: start_repository.gitaly_repository,
dry_run: dry_run
) )
response = GitalyClient.call( response = GitalyClient.call(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment