Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
2e6bbb12
Commit
2e6bbb12
authored
Jul 01, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor can_be_merged logic for merge request
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
804168e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
app/models/merge_request.rb
app/models/merge_request.rb
+1
-7
app/models/repository.rb
app/models/repository.rb
+9
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+14
-0
No files found.
app/models/merge_request.rb
View file @
2e6bbb12
...
...
@@ -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
...
...
app/models/repository.rb
View file @
2e6bbb12
...
...
@@ -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
...
...
spec/models/repository_spec.rb
View file @
2e6bbb12
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment