Commit ce7eb4e4 authored by Sean McGivern's avatar Sean McGivern Committed by Fatih Acet

Add more tests for conflicts

parent f322c302
No related merge requests found
...@@ -139,7 +139,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -139,7 +139,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: @merge_request.conflicts render json: @merge_request.conflicts
else else
render json: { render json: {
message: 'Unable to resolve conflicts in the web interface for this merge request', message: 'Unable to resolve conflicts in the web interface for this merge request.',
type: 'error' type: 'error'
} }
end end
......
...@@ -46,7 +46,7 @@ module Gitlab ...@@ -46,7 +46,7 @@ module Gitlab
end end
<<EOM.chomp <<EOM.chomp
Merge branch '#{merge_request.source_branch}' into '#{merge_request.target_branch}' Merge branch '#{merge_request.target_branch}' into '#{merge_request.source_branch}'
# Conflicts: # Conflicts:
#{conflict_filenames.join("\n")} #{conflict_filenames.join("\n")}
......
...@@ -5,7 +5,7 @@ describe Projects::MergeRequestsController do ...@@ -5,7 +5,7 @@ describe Projects::MergeRequestsController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:merge_request_with_conflicts) do let(:merge_request_with_conflicts) do
create(:merge_request, source_branch: 'conflict-a', target_branch: 'conflict-b', source_project: project) do |mr| create(:merge_request, source_branch: 'conflict-resolvable', target_branch: 'conflict-start', source_project: project) do |mr|
mr.mark_as_unmergeable mr.mark_as_unmergeable
end end
end end
...@@ -625,7 +625,7 @@ describe Projects::MergeRequestsController do ...@@ -625,7 +625,7 @@ describe Projects::MergeRequestsController do
context 'with valid params' do context 'with valid params' do
before do before do
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'head', resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_14' => 'head',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_9_9' => 'head', '6eb14e00385d2fb284765eb1cd8d420d33d63fc9_9_9' => 'head',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21' => 'origin', '6eb14e00385d2fb284765eb1cd8d420d33d63fc9_21_21' => 'origin',
'6eb14e00385d2fb284765eb1cd8d420d33d63fc9_49_49' => 'origin') '6eb14e00385d2fb284765eb1cd8d420d33d63fc9_49_49' => 'origin')
...@@ -636,14 +636,14 @@ describe Projects::MergeRequestsController do ...@@ -636,14 +636,14 @@ describe Projects::MergeRequestsController do
expect(merge_request_with_conflicts.source_branch_head.message).to include('Commit message') expect(merge_request_with_conflicts.source_branch_head.message).to include('Commit message')
end end
it 'returns an OK resposne' do it 'returns an OK response' do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
end end
end end
context 'when sections are missing' do context 'when sections are missing' do
before do before do
resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_4_4' => 'head') resolve_conflicts('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_14' => 'head')
end end
it 'returns a 400 error' do it 'returns a 400 error' do
......
require 'spec_helper'
feature 'Merge request conflict resolution', js: true, feature: true do
include WaitForAjax
let(:user) { create(:user) }
let(:project) { create(:project) }
def create_merge_request(source_branch)
create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start', source_project: project) do |mr|
mr.mark_as_unmergeable
end
end
context 'when a merge request can be resolved in the UI' do
let(:merge_request) { create_merge_request('conflict-resolvable') }
before do
project.team << [user, :developer]
login_as(user)
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it 'shows a link to the conflict resolution page' do
expect(page).to have_link('conflicts', href: /\/conflicts\Z/)
end
context 'visiting the conflicts resolution page' do
before { click_link('conflicts', href: /\/conflicts\Z/) }
it 'shows the conflicts' do
expect(find('#conflicts')).to have_content('popen.rb')
end
end
end
UNRESOLVABLE_CONFLICTS = {
'conflict-too-large' => 'when the conflicts contain a large file',
'conflict-binary-file' => 'when the conflicts contain a binary file',
'conflict-contains-conflict-markers' => 'when the conflicts contain a file with ambiguous conflict markers',
'conflict-missing-side' => 'when the conflicts contain a file edited in one branch and deleted in another'
}
UNRESOLVABLE_CONFLICTS.each do |source_branch, description|
context description do
let(:merge_request) { create_merge_request(source_branch) }
before do
project.team << [user, :developer]
login_as(user)
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it 'does not show a link to the conflict resolution page' do
expect(page).not_to have_link('conflicts', href: /\/conflicts\Z/)
end
it 'shows an error if the conflicts page is visited directly' do
visit current_url + '/conflicts'
wait_for_ajax
expect(find('#conflicts')).to have_content('Unable to resolve conflicts')
end
end
end
end
require 'spec_helper' require 'spec_helper'
describe Gitlab::Conflict::FileCollection, lib: true do describe Gitlab::Conflict::FileCollection, lib: true do
let(:merge_request) { create(:merge_request, source_branch: 'conflict-a', target_branch: 'conflict-b') } let(:merge_request) { create(:merge_request, source_branch: 'conflict-resolvable', target_branch: 'conflict-start') }
let(:file_collection) { Gitlab::Conflict::FileCollection.new(merge_request) } let(:file_collection) { Gitlab::Conflict::FileCollection.new(merge_request) }
describe '#files' do describe '#files' do
...@@ -13,7 +13,7 @@ describe Gitlab::Conflict::FileCollection, lib: true do ...@@ -13,7 +13,7 @@ describe Gitlab::Conflict::FileCollection, lib: true do
describe '#default_commit_message' do describe '#default_commit_message' do
it 'matches the format of the git CLI commit message' do it 'matches the format of the git CLI commit message' do
expect(file_collection.default_commit_message).to eq(<<EOM.chomp) expect(file_collection.default_commit_message).to eq(<<EOM.chomp)
Merge branch 'conflict-a' into 'conflict-b' Merge branch 'conflict-start' into 'conflict-resolvable'
# Conflicts: # Conflicts:
# files/ruby/popen.rb # files/ruby/popen.rb
......
...@@ -4,9 +4,9 @@ describe Gitlab::Conflict::File, lib: true do ...@@ -4,9 +4,9 @@ describe Gitlab::Conflict::File, lib: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:rugged) { repository.rugged } let(:rugged) { repository.rugged }
let(:their_commit) { rugged.branches['conflict-a'].target } let(:their_commit) { rugged.branches['conflict-start'].target }
let(:our_commit) { rugged.branches['conflict-b'].target } let(:our_commit) { rugged.branches['conflict-resolvable'].target }
let(:merge_request) { create(:merge_request, source_branch: 'conflict-b', target_branch: 'conflict-a', source_project: project) } let(:merge_request) { create(:merge_request, source_branch: 'conflict-resolvable', target_branch: 'conflict-start', source_project: project) }
let(:index) { rugged.merge_commits(our_commit, their_commit) } let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last } let(:conflict) { index.conflicts.last }
let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') } let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') }
......
...@@ -741,4 +741,56 @@ describe MergeRequest, models: true do ...@@ -741,4 +741,56 @@ describe MergeRequest, models: true do
end end
end end
end end
describe '#can_resolve_conflicts_in_ui?' do
def create_merge_request(source_branch)
create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start') do |mr|
mr.mark_as_unmergeable
end
end
it 'returns a falsey value when the MR can be merged without conflicts' do
merge_request = create_merge_request('master')
merge_request.mark_as_mergeable
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a falsey value when the MR does not support new diff notes' do
merge_request = create_merge_request('conflict-resolvable')
merge_request.merge_request_diff.update_attributes(start_commit_sha: nil)
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a falsey value when the conflicts contain a large file' do
merge_request = create_merge_request('conflict-too-large')
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a falsey value when the conflicts contain a binary file' do
merge_request = create_merge_request('conflict-binary-file')
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a falsey value when the conflicts contain a file with ambiguous conflict markers' do
merge_request = create_merge_request('conflict-contains-conflict-markers')
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a falsey value when the conflicts contain a file edited in one branch and deleted in another' do
merge_request = create_merge_request('conflict-missing-side')
expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey
end
it 'returns a truthy value when the conflicts are resolvable in the UI' do
merge_request = create_merge_request('conflict-resolvable')
expect(merge_request.can_resolve_conflicts_in_ui?).to be_truthy
end
end
end end
...@@ -5,27 +5,31 @@ module TestEnv ...@@ -5,27 +5,31 @@ module TestEnv
# When developing the seed repository, comment out the branch you will modify. # When developing the seed repository, comment out the branch you will modify.
BRANCH_SHA = { BRANCH_SHA = {
'empty-branch' => '7efb185', 'empty-branch' => '7efb185',
'ends-with.json' => '98b0d8b3', 'ends-with.json' => '98b0d8b3',
'flatten-dir' => 'e56497b', 'flatten-dir' => 'e56497b',
'feature' => '0b4bc9a', 'feature' => '0b4bc9a',
'feature_conflict' => 'bb5206f', 'feature_conflict' => 'bb5206f',
'fix' => '48f0be4', 'fix' => '48f0be4',
'improve/awesome' => '5937ac0', 'improve/awesome' => '5937ac0',
'markdown' => '0ed8c6c', 'markdown' => '0ed8c6c',
'lfs' => 'be93687', 'lfs' => 'be93687',
'master' => '5937ac0', 'master' => '5937ac0',
"'test'" => 'e56497b', "'test'" => 'e56497b',
'orphaned-branch' => '45127a9', 'orphaned-branch' => '45127a9',
'binary-encoding' => '7b1cf43', 'binary-encoding' => '7b1cf43',
'gitattributes' => '5a62481', 'gitattributes' => '5a62481',
'conflict-a' => 'dfdd207', 'expand-collapse-diffs' => '4842455',
'conflict-b' => '4e75a62', 'expand-collapse-files' => '025db92',
'expand-collapse-diffs' => '4842455', 'expand-collapse-lines' => '238e82d',
'expand-collapse-files' => '025db92', 'video' => '8879059',
'expand-collapse-lines' => '238e82d', 'crlf-diff' => '5938907',
'video' => '8879059', 'conflict-start' => '14fa46b',
'crlf-diff' => '5938907' 'conflict-resolvable' => '1450cd6',
'conflict-binary-file' => '259a6fb',
'conflict-contains-conflict-markers' => '5e0964c',
'conflict-missing-side' => 'eb227b3',
'conflict-too-large' => '39fa04f',
} }
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
......
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