Commit 207522f9 authored by Rubén Dávila's avatar Rubén Dávila Committed by Robert Speicher

Some refactor to the revert commit creation.

* Not required to run hooks since it's an internal commit
parent f56ee9d3
......@@ -193,10 +193,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def revert
@repository.revert_merge(current_user, @merge_request.merge_commit_sha, @merge_request.reverse_branch_name)
@repository.revert_merge(current_user, @merge_request)
url_params = { merge_request: {
source_branch: @merge_request.reverse_branch_name,
source_branch: @merge_request.revert_branch_name,
target_branch: @merge_request.target_branch,
source_project_id: @merge_request.target_project_id,
target_project_id: @merge_request.target_project_id
......
......@@ -534,7 +534,7 @@ class MergeRequest < ActiveRecord::Base
[diff_base_commit, last_commit]
end
def reverse_branch_name
def revert_branch_name
"revert-#{id}-#{target_branch}"
end
end
......@@ -626,25 +626,28 @@ class Repository
merge_commit_sha
end
def revert_merge(user, merge_commit_id, revert_branch_name)
find_or_create_branch(user, revert_branch_name, merge_commit_id)
def revert_merge(user, merge_request)
revert_branch_name = merge_request.revert_branch_name
merge_commit_id = merge_request.merge_commit_sha
# branch exists and it's highly probable that it has the revert commit
return if find_branch(revert_branch_name)
add_branch(user, revert_branch_name, merge_commit_id)
new_index = rugged.revert_commit(merge_commit_id, merge_commit_id, mainline: 1)
committer = user_to_committer(user)
commit_with_hooks(user, revert_branch_name) do |ref|
options = {
message: 'Revert MR',
author: committer,
committer: committer,
tree: new_index.write_tree(rugged),
parents: [rugged.lookup(merge_commit_id)],
update_ref: ref
}
Rugged::Commit.create(rugged, options)
end
options = {
message: "Revert \"#{merge_request.title}\"",
author: committer,
committer: committer,
tree: new_index.write_tree(rugged),
parents: [rugged.lookup(merge_commit_id)],
update_ref: "refs/heads/#{revert_branch_name}"
}
Rugged::Commit.create(rugged, options)
end
def merged_to_root_ref?(branch_name)
......
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