Commit 459e6d34 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'refactor-can-be-merge' into 'master'

Refactor can_be_merged logic for merge request

Some refactoring after !918

cc @DouweM @rspeicher
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

See merge request !919
parents 804168e1 2e6bbb12
...@@ -209,13 +209,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -209,13 +209,7 @@ class MergeRequest < ActiveRecord::Base
if for_fork? if for_fork?
Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged? Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
else else
rugged = project.repository.rugged project.repository.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 end
if can_be_merged if can_be_merged
......
...@@ -422,6 +422,15 @@ class Repository ...@@ -422,6 +422,15 @@ class Repository
} }
end 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 private
def cache def cache
......
...@@ -33,4 +33,18 @@ describe Repository do ...@@ -33,4 +33,18 @@ describe Repository do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
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 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