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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d99d5198
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
8 deletions
+44
-8
app/models/merge_request.rb
app/models/merge_request.rb
+27
-8
spec/models/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
...
@@ -177,8 +177,8 @@ class MergeRequest < ActiveRecord::Base
def
diff_base_commit
def
diff_base_commit
if
persisted?
if
persisted?
merge_request_diff
.
base_commit
merge_request_diff
.
base_commit
els
if
diff_start_commit
&&
diff_head_commit
els
e
self
.
target_project
.
merge_base_commit
(
diff_start_sha
,
diff_head_sha
)
branch_merge_base_commit
end
end
end
end
...
@@ -239,6 +239,15 @@ class MergeRequest < ActiveRecord::Base
...
@@ -239,6 +239,15 @@ class MergeRequest < ActiveRecord::Base
target_project
.
repository
.
commit
(
target_branch
)
if
target_branch_ref
target_project
.
repository
.
commit
(
target_branch
)
if
target_branch_ref
end
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
def
target_branch_sha
@target_branch_sha
||
target_branch_head
.
try
(
:sha
)
@target_branch_sha
||
target_branch_head
.
try
(
:sha
)
end
end
...
@@ -247,15 +256,25 @@ class MergeRequest < ActiveRecord::Base
...
@@ -247,15 +256,25 @@ class MergeRequest < ActiveRecord::Base
@source_branch_sha
||
source_branch_head
.
try
(
:sha
)
@source_branch_sha
||
source_branch_head
.
try
(
:sha
)
end
end
def
branch_merge_base_sha
branch_merge_base_commit
.
try
(
:sha
)
end
def
diff_refs
def
diff_refs
if
merge_request_diff
if
merge_request_diff
merge_request_diff
.
diff_refs
merge_request_diff
.
diff_refs
elsif
diff_start_commit
||
diff_base_commit
else
Gitlab
::
Diff
::
DiffRefs
.
new
(
start_sha
=
target_branch_sha
base_sha:
diff_base_sha
,
head_sha
=
source_branch_sha
start_sha:
diff_start_sha
,
base_sha
=
branch_merge_base_sha
head_sha:
diff_head_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
end
end
...
...
spec/models/merge_request_spec.rb
View file @
d99d5198
...
@@ -691,4 +691,21 @@ describe MergeRequest, models: true do
...
@@ -691,4 +691,21 @@ describe MergeRequest, models: true do
subject
.
reload_diff
subject
.
reload_diff
end
end
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
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