Commit a5245fd8 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-can-be-merged' into 'master'

Move mergablility check to Gitaly

Closes gitaly#889

See merge request gitlab-org/gitlab-ce!20019
parents 00518d26 46b56b18
...@@ -850,7 +850,7 @@ class Repository ...@@ -850,7 +850,7 @@ class Repository
@root_ref_sha ||= commit(root_ref).sha @root_ref_sha ||= commit(root_ref).sha
end end
delegate :merged_branch_names, :can_be_merged?, to: :raw_repository delegate :merged_branch_names, to: :raw_repository
def merge_base(first_commit_id, second_commit_id) def merge_base(first_commit_id, second_commit_id)
first_commit_id = commit(first_commit_id).try(:id) || first_commit_id first_commit_id = commit(first_commit_id).try(:id) || first_commit_id
......
...@@ -1413,13 +1413,8 @@ module Gitlab ...@@ -1413,13 +1413,8 @@ module Gitlab
end end
def can_be_merged?(source_sha, target_branch) def can_be_merged?(source_sha, target_branch)
gitaly_migrate(:can_be_merged) do |is_enabled| target_sha = find_branch(target_branch, true).target
if is_enabled !gitaly_conflicts_client(source_sha, target_sha).conflicts?
gitaly_can_be_merged?(source_sha, find_branch(target_branch, true).target)
else
rugged_can_be_merged?(source_sha, target_branch)
end
end
end end
def search_files_by_name(query, ref) def search_files_by_name(query, ref)
...@@ -2232,14 +2227,6 @@ module Gitlab ...@@ -2232,14 +2227,6 @@ module Gitlab
run_git(['fetch', remote_name], env: env).last.zero? run_git(['fetch', remote_name], env: env).last.zero?
end end
def gitaly_can_be_merged?(their_commit, our_commit)
!gitaly_conflicts_client(our_commit, their_commit).conflicts?
end
def rugged_can_be_merged?(their_commit, our_commit)
!rugged.merge_commits(our_commit, their_commit).conflicts?
end
def gitlab_projects_error def gitlab_projects_error
raise CommandError, @gitlab_projects.output raise CommandError, @gitlab_projects.output
end end
......
...@@ -434,44 +434,34 @@ describe Repository do ...@@ -434,44 +434,34 @@ describe Repository do
end end
describe '#can_be_merged?' do describe '#can_be_merged?' do
shared_examples 'can be merged' do context 'mergeable branches' do
context 'mergeable branches' do subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') }
subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'non-mergeable branches without conflict sides missing' do
subject { repository.can_be_merged?('bb5206fee213d983da88c47f9cf4cc6caf9c66dc', 'feature') }
it { is_expected.to be_falsey }
end
context 'non-mergeable branches with conflict sides missing' do context 'non-mergeable branches without conflict sides missing' do
subject { repository.can_be_merged?('conflict-missing-side', 'conflict-start') } subject { repository.can_be_merged?('bb5206fee213d983da88c47f9cf4cc6caf9c66dc', 'feature') }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'non merged branch' do context 'non-mergeable branches with conflict sides missing' do
subject { repository.merged_to_root_ref?('fix') } subject { repository.can_be_merged?('conflict-missing-side', 'conflict-start') }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'non existent branch' do context 'non merged branch' do
subject { repository.merged_to_root_ref?('non_existent_branch') } subject { repository.merged_to_root_ref?('fix') }
it { is_expected.to be_nil } it { is_expected.to be_falsey }
end
end end
context 'when Gitaly can_be_merged feature is enabled' do context 'non existent branch' do
it_behaves_like 'can be merged' subject { repository.merged_to_root_ref?('non_existent_branch') }
end
context 'when Gitaly can_be_merged feature is disabled', :disable_gitaly do it { is_expected.to be_nil }
it_behaves_like 'can be merged'
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