BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d99d5198
Unverified
Commit
d99d5198
authored
Aug 08, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MergeRequest#branch_merge_base_commit method
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
08f5f897
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
8 deletions
+44
-8
merge_request.rb
app/models/merge_request.rb
+27
-8
merge_request_spec.rb
spec/models/merge_request_spec.rb
+17
-0
No files found.
app/models/merge_request.rb
View file @
d99d5198
...
...
@@ -177,8 +177,8 @@ class MergeRequest < ActiveRecord::Base
def
diff_base_commit
if
persisted?
merge_request_diff
.
base_commit
els
if
diff_start_commit
&&
diff_head_commit
self
.
target_project
.
merge_base_commit
(
diff_start_sha
,
diff_head_sha
)
els
e
branch_merge_base_commit
end
end
...
...
@@ -239,6 +239,15 @@ class MergeRequest < ActiveRecord::Base
target_project
.
repository
.
commit
(
target_branch
)
if
target_branch_ref
end
def
branch_merge_base_commit
start_sha
=
target_branch_sha
head_sha
=
source_branch_sha
if
start_sha
&&
head_sha
target_project
.
merge_base_commit
(
start_sha
,
head_sha
)
end
end
def
target_branch_sha
@target_branch_sha
||
target_branch_head
.
try
(
:sha
)
end
...
...
@@ -247,15 +256,25 @@ class MergeRequest < ActiveRecord::Base
@source_branch_sha
||
source_branch_head
.
try
(
:sha
)
end
def
branch_merge_base_sha
branch_merge_base_commit
.
try
(
:sha
)
end
def
diff_refs
if
merge_request_diff
merge_request_diff
.
diff_refs
elsif
diff_start_commit
||
diff_base_commit
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
diff_base_sha
,
start_sha:
diff_start_sha
,
head_sha:
diff_head_sha
)
else
start_sha
=
target_branch_sha
head_sha
=
source_branch_sha
base_sha
=
branch_merge_base_sha
if
start_sha
||
base_sha
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
base_sha
,
start_sha:
start_sha
,
head_sha:
head_sha
)
end
end
end
...
...
spec/models/merge_request_spec.rb
View file @
d99d5198
...
...
@@ -691,4 +691,21 @@ describe MergeRequest, models: true do
subject
.
reload_diff
end
end
describe
'#branch_merge_base_commit'
do
context
'source and target branch exist'
do
it
{
expect
(
subject
.
branch_merge_base_commit
.
sha
).
to
eq
(
'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
)
}
it
{
expect
(
subject
.
branch_merge_base_commit
).
to
be_a
(
Commit
)
}
end
context
'when the target branch does not exist'
do
before
do
subject
.
project
.
repository
.
raw_repository
.
delete_branch
(
subject
.
target_branch
)
end
it
'returns nil'
do
expect
(
subject
.
branch_merge_base_commit
).
to
be_nil
end
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