Commit d133bd7f authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Support merge to ref for merge-commit and squash

Adds the ground work for writing into
the merge ref refs/merge-requests/:iid/merge the
merge result between source and target branches of
a MR, without further side-effects such as
mailing, MR updates and target branch changes.
parent 08dc0551
......@@ -15,7 +15,10 @@ def hooks_validation_pass?(_merge_request)
# Overridden in EE.
def hooks_validation_error(_merge_request)
<<<<<<< HEAD
# No-op
=======
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
end
def source
......@@ -28,6 +31,7 @@ def source
private
<<<<<<< HEAD
# Overridden in EE.
def error_check!
# No-op
......@@ -37,6 +41,8 @@ def raise_error(message)
raise MergeError, message
end
=======
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
def handle_merge_error(*args)
# No-op
end
......
......@@ -14,11 +14,19 @@ class MergeToRefService < MergeRequests::MergeBaseService
def execute(merge_request)
@merge_request = merge_request
<<<<<<< HEAD
validate!
commit_id = commit
raise_error('Conflicts detected during merge') unless commit_id
=======
error_check!
commit_id = commit
raise MergeError, 'Conflicts detected during merge' unless commit_id
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
success(commit_id: commit_id)
rescue MergeError => error
......@@ -27,6 +35,7 @@ def execute(merge_request)
private
<<<<<<< HEAD
def validate!
authorization_check!
error_check!
......@@ -39,6 +48,11 @@ def error_check!
if Feature.disabled?(:merge_to_tmp_merge_ref_path, project)
'Feature is not enabled'
elsif !merge_method_supported?
=======
def error_check!
error =
if !merge_method_supported?
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
"#{project.human_merge_method} to #{target_ref} is currently not supported."
elsif !hooks_validation_pass?(merge_request)
hooks_validation_error(merge_request)
......@@ -50,6 +64,7 @@ def error_check!
'No source for merge'
end
<<<<<<< HEAD
raise_error(error) if error
end
......@@ -57,6 +72,9 @@ def authorization_check!
unless Ability.allowed?(current_user, :admin_merge_request, project)
raise_error("You are not allowed to merge to this ref")
end
=======
raise MergeError, error if error
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
end
def target_ref
......
......@@ -3,6 +3,7 @@
require 'spec_helper'
describe MergeRequests::MergeToRefService do
<<<<<<< HEAD
shared_examples_for 'MergeService for target ref' do
it 'target_ref has the same state of target branch' do
repo = merge_request.target_project.repository
......@@ -19,6 +20,8 @@
end
end
=======
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
set(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :simple) }
let(:project) { merge_request.project }
......@@ -74,6 +77,7 @@ def process_merge_to_ref
process_merge_to_ref
end
<<<<<<< HEAD
it 'returns error when feature is disabled' do
stub_feature_flags(merge_to_tmp_merge_ref_path: false)
......@@ -83,6 +87,8 @@ def process_merge_to_ref
expect(result[:message]).to eq('Feature is not enabled')
end
=======
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
it 'returns an error when the failing to process the merge' do
allow(project.repository).to receive(:merge_to_ref).and_return(nil)
......@@ -101,6 +107,25 @@ def process_merge_to_ref
MergeRequests::MergeService.new(project, user, {})
end
<<<<<<< HEAD
=======
shared_examples_for 'MergeService for target ref' do
it 'target_ref has the same state of target branch' do
repo = merge_request.target_project.repository
process_merge_to_ref
merge_service.execute(merge_request)
ref_commits = repo.commits(merge_request.merge_ref_path, limit: 3)
target_branch_commits = repo.commits(merge_request.target_branch, limit: 3)
ref_commits.zip(target_branch_commits).each do |ref_commit, target_branch_commit|
expect(ref_commit.parents).to eq(target_branch_commit.parents)
end
end
end
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
context 'when merge commit' do
it_behaves_like 'MergeService for target ref'
end
......@@ -185,6 +210,7 @@ def process_merge_to_ref
it { expect(todo).not_to be_done }
end
<<<<<<< HEAD
it 'returns error when user has no authorization to admin the merge request' do
unauthorized_user = create(:user)
......@@ -197,5 +223,7 @@ def process_merge_to_ref
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('You are not allowed to merge to this ref')
end
=======
>>>>>>> 89c57ca2673... Support merge to ref for merge-commit and squash
end
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