Commit 3b84cfdc authored by Sean McGivern's avatar Sean McGivern Committed by Fatih Acet

Use same resolution format on FE and BE

parent 76cd67b0
......@@ -287,7 +287,7 @@ window.MergeConflictDataProvider = class MergeConflictDataProvider {
getCommitData() {
return {
commitMessage: this.vueInstance.conflictsData.commitMessage,
commit_message: this.vueInstance.conflictsData.commitMessage,
sections: this.vueInstance.resolutionData
}
}
......
......@@ -44,9 +44,9 @@ module Gitlab
section_id ||= line_code(line)
case resolution[section_id]
when 'ours'
when 'head'
next unless line.type == 'new'
when 'theirs'
when 'origin'
next unless line.type == 'old'
else
raise MissingResolution, "Missing resolution for section ID: #{section_id}"
......
......@@ -20,10 +20,11 @@ module Gitlab
@merge_index ||= repository.rugged.merge_commits(our_commit, their_commit)
end
def resolve_conflicts!(resolutions, commit_message, user:)
def resolve_conflicts!(params, user:)
resolutions = params[:sections]
commit_message = params[:commit_message] || default_commit_message
rugged = repository.rugged
committer = repository.user_to_committer(user)
commit_message ||= default_commit_message
files.each do |file|
file.resolve!(resolutions, index: merge_index, rugged: rugged)
......
......@@ -549,7 +549,7 @@ describe Projects::MergeRequestsController do
end
it 'returns JSON with a message' do
expect(json_response.keys).to contain_exactly('message')
expect(json_response.keys).to contain_exactly('message', 'type')
end
end
......@@ -613,30 +613,31 @@ describe Projects::MergeRequestsController do
let(:json_response) { JSON.parse(response.body) }
let!(:original_head_sha) { merge_request_with_conflicts.diff_head_sha }
def resolve_conflicts(params)
def resolve_conflicts(sections)
post :resolve_conflicts,
namespace_id: merge_request_with_conflicts.project.namespace.to_param,
project_id: merge_request_with_conflicts.project.to_param,
id: merge_request_with_conflicts.iid,
format: 'json',
merge_request: params
sections: sections,
commit_message: 'Commit message'
end
context 'with valid params' do
before do
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'ours',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_9_9' => 'ours',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21' => 'theirs',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_49_49' => 'theirs')
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'head',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_9_9' => 'head',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21' => 'origin',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_49_49' => 'origin')
end
it 'creates a new commit on the branch' do
expect(original_head_sha).not_to eq(merge_request_with_conflicts.source_branch_head.sha)
expect(merge_request_with_conflicts.source_branch_head.message).to include('Merge branch')
expect(merge_request_with_conflicts.source_branch_head.message).to include('Commit message')
end
it 'redirects to the MR show page' do
expect(response).to redirect_to([merge_request_with_conflicts.target_project.namespace.becomes(Namespace), merge_request_with_conflicts.target_project, merge_request_with_conflicts])
it 'returns an OK resposne' do
expect(response).to have_http_status(:ok)
end
context 'undoing the resolution' do
......@@ -655,7 +656,7 @@ describe Projects::MergeRequestsController do
context 'when sections are missing' do
before do
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'ours')
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'head')
end
it 'returns a 400 error' do
......
......@@ -15,7 +15,7 @@ describe Gitlab::Conflict::File, lib: true do
let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact }
context 'when resolving everything to the same side' do
let(:resolution_hash) { section_keys.map { |key| [key, 'ours'] }.to_h }
let(:resolution_hash) { section_keys.map { |key| [key, 'head'] }.to_h }
let(:resolved_lines) { conflict_file.resolve_lines(resolution_hash) }
let(:expected_lines) { conflict_file.lines.reject { |line| line.type == 'old' } }
......@@ -30,7 +30,7 @@ describe Gitlab::Conflict::File, lib: true do
context 'with mixed resolutions' do
let(:resolution_hash) do
section_keys.map.with_index { |key, i| [key, i.even? ? 'ours' : 'theirs'] }.to_h
section_keys.map.with_index { |key, i| [key, i.even? ? 'head' : 'origin'] }.to_h
end
let(:resolved_lines) { conflict_file.resolve_lines(resolution_hash) }
......
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