BigW Consortium Gitlab

Commit 6ae1a73c by Lin Jen-Shin

Pass source_branch properly for cherry-pick/revert

parent 65806ec6
......@@ -962,14 +962,16 @@ class Repository
end
end
def revert(user, commit, base_branch, revert_tree_id = nil)
def revert(
user, commit, base_branch, revert_tree_id = nil,
source_branch: nil, source_project: project)
revert_tree_id ||= check_revert_content(commit, base_branch)
return false unless revert_tree_id
GitOperationService.new(user, self).with_branch(
base_branch,
source_commit: commit) do
source_branch: source_branch, source_project: source_project) do
source_sha = find_branch(base_branch).dereferenced_target.sha
committer = user_to_committer(user)
......@@ -983,14 +985,16 @@ class Repository
end
end
def cherry_pick(user, commit, base_branch, cherry_pick_tree_id = nil)
def cherry_pick(
user, commit, base_branch, cherry_pick_tree_id = nil,
source_branch: nil, source_project: project)
cherry_pick_tree_id ||= check_cherry_pick_content(commit, base_branch)
return false unless cherry_pick_tree_id
GitOperationService.new(user, self).with_branch(
base_branch,
source_commit: commit) do
source_branch: source_branch, source_project: source_project) do
source_sha = find_branch(base_branch).dereferenced_target.sha
committer = user_to_committer(user)
......
......@@ -31,7 +31,14 @@ module Commits
if tree_id
validate_target_branch(into) if @create_merge_request
repository.public_send(action, current_user, @commit, into, tree_id)
repository.public_send(
action,
current_user,
@commit,
into,
tree_id,
source_branch: @target_branch)
success
else
error_msg = "Sorry, we cannot #{action.to_s.dasherize} this #{@commit.change_type_title} automatically.
......
......@@ -25,21 +25,15 @@ GitOperationService = Struct.new(:user, :repository) do
end
end
# Whenever `source_branch` or `source_commit` is passed, if `branch`
# doesn't exist, it would be created from `source_branch` or
# `source_commit`. Should only pass one of them, not both.
# Whenever `source_branch` is passed, if `branch` doesn't exist,
# it would be created from `source_branch`.
# If `source_project` is passed, and the branch doesn't exist,
# it would try to find the source from it instead of current repository.
def with_branch(
branch_name,
source_branch: nil,
source_commit: nil,
source_project: repository.project)
if source_commit && source_branch
raise ArgumentError, 'Should pass only :source_branch or :source_commit'
end
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
oldrev = Gitlab::Git::BLANK_SHA
......@@ -62,13 +56,13 @@ GitOperationService = Struct.new(:user, :repository) do
" #{source_project.path_with_namespace}")
end
elsif source_commit || source_branch
newrev = (source_commit || repository.commit(source_branch)).try(:sha)
elsif source_branch
newrev = repository.commit(source_branch).try(:sha)
unless newrev
raise Repository::CommitError.new(
"Cannot find branch #{branch_name} nor" \
" #{source_commit.try(:sha) || source_branch} from" \
" #{source_branch} from" \
" #{repository.project.path_with_namespace}")
end
......
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