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