summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-02-16 18:24:56 -0600
committerDouwe Maan <douwe@selenight.nl>2017-03-02 17:41:05 -0600
commit6cc4cf1e151fb8da16796d7bbab16bc8a1ac08b6 (patch)
treedbc7105aa4ecd6498a9354ad6d9c141fb93d277f /app/models
parentefff35e96873bd3bea0afceb1d3cd102280813f5 (diff)
downloadgitlab-ce-6cc4cf1e151fb8da16796d7bbab16bc8a1ac08b6.tar.gz
Fix cherry-picking or reverting through an MR
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index d410d60dbad..4f8b436ee16 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -862,17 +862,18 @@ class Repository
end
def revert(
- user, commit, branch_name, revert_tree_id = nil,
+ user, commit, branch_name,
start_branch_name: nil, start_project: project)
- revert_tree_id ||= check_revert_content(commit, branch_name)
-
- return false unless revert_tree_id
-
GitOperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
start_project: start_project) do |start_commit|
+ revert_tree_id = check_revert_content(commit, start_commit.sha)
+ unless revert_tree_id
+ raise Repository::CommitError.new('Failed to revert commit')
+ end
+
committer = user_to_committer(user)
Rugged::Commit.create(rugged,
@@ -885,17 +886,18 @@ class Repository
end
def cherry_pick(
- user, commit, branch_name, cherry_pick_tree_id = nil,
+ user, commit, branch_name,
start_branch_name: nil, start_project: project)
- cherry_pick_tree_id ||= check_cherry_pick_content(commit, branch_name)
-
- return false unless cherry_pick_tree_id
-
GitOperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
start_project: start_project) do |start_commit|
+ cherry_pick_tree_id = check_cherry_pick_content(commit, start_commit.sha)
+ unless cherry_pick_tree_id
+ raise Repository::CommitError.new('Failed to cherry-pick commit')
+ end
+
committer = user_to_committer(user)
Rugged::Commit.create(rugged,
@@ -919,9 +921,8 @@ class Repository
end
end
- def check_revert_content(target_commit, branch_name)
- source_sha = commit(branch_name).sha
- args = [target_commit.sha, source_sha]
+ def check_revert_content(target_commit, source_sha)
+ args = [target_commit.sha, source_sha]
args << { mainline: 1 } if target_commit.merge_commit?
revert_index = rugged.revert_commit(*args)
@@ -933,9 +934,8 @@ class Repository
tree_id
end
- def check_cherry_pick_content(target_commit, branch_name)
- source_sha = commit(branch_name).sha
- args = [target_commit.sha, source_sha]
+ def check_cherry_pick_content(target_commit, source_sha)
+ args = [target_commit.sha, source_sha]
args << 1 if target_commit.merge_commit?
cherry_pick_index = rugged.cherrypick_commit(*args)