Commit 2e6bbb12 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor can_be_merged logic for merge request

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 804168e1
......@@ -209,13 +209,7 @@ class MergeRequest < ActiveRecord::Base
if for_fork?
Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
else
rugged = project.repository.rugged
our_commit = rugged.branches[target_branch].target
their_commit = rugged.branches[source_branch].target
if our_commit && their_commit
!rugged.merge_commits(our_commit, their_commit).conflicts?
end
project.repository.can_be_merged?(source_branch, target_branch)
end
if can_be_merged
......
......@@ -422,6 +422,15 @@ class Repository
}
end
def can_be_merged?(source_branch, target_branch)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.branches[source_branch].target
if our_commit && their_commit
!rugged.merge_commits(our_commit, their_commit).conflicts?
end
end
private
def cache
......
......@@ -33,4 +33,18 @@ describe Repository do
it { is_expected.to be_nil }
end
end
describe :can_be_merged? do
context 'mergeable branches' do
subject { repository.can_be_merged?('feature', 'master') }
it { is_expected.to be_truthy }
end
context 'non-mergeable branches' do
subject { repository.can_be_merged?('feature_conflict', 'feature') }
it { is_expected.to be_falsey }
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