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
Jérome Perrin
gitlab-ce
Commits
49d63dc1
Commit
49d63dc1
authored
Aug 15, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix and refactor merge request diff_refs method
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
643a368f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
27 deletions
+11
-27
app/models/diff_note.rb
app/models/diff_note.rb
+1
-5
app/models/merge_request.rb
app/models/merge_request.rb
+2
-15
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+7
-6
No files found.
app/models/diff_note.rb
View file @
49d63dc1
...
@@ -79,11 +79,7 @@ class DiffNote < Note
...
@@ -79,11 +79,7 @@ class DiffNote < Note
end
end
def
noteable_diff_refs
def
noteable_diff_refs
if
noteable
.
respond_to?
(
:diff_sha_refs
)
noteable
.
diff_refs
noteable
.
diff_sha_refs
else
noteable
.
diff_refs
end
end
end
def
set_original_position
def
set_original_position
...
...
app/models/merge_request.rb
View file @
49d63dc1
...
@@ -270,7 +270,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -270,7 +270,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diff_refs
def
diff_refs
if
persisted
?
if
merge_request_diff
&&
merge_request_diff
.
diff_refs_by_sha
?
merge_request_diff
.
diff_refs
merge_request_diff
.
diff_refs
else
else
start_sha
=
target_branch_sha
start_sha
=
target_branch_sha
...
@@ -287,19 +287,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -287,19 +287,6 @@ class MergeRequest < ActiveRecord::Base
end
end
end
end
# Return diff_refs instance trying to not touch the git repository
def
diff_sha_refs
if
merge_request_diff
&&
merge_request_diff
.
diff_refs_by_sha?
return
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
merge_request_diff
.
base_commit_sha
,
start_sha:
merge_request_diff
.
start_commit_sha
,
head_sha:
merge_request_diff
.
head_commit_sha
)
else
diff_refs
end
end
def
validate_branches
def
validate_branches
if
target_project
==
source_project
&&
target_branch
==
source_branch
if
target_project
==
source_project
&&
target_branch
==
source_branch
errors
.
add
:branch_conflict
,
"You can not use same project/branch for source and target"
errors
.
add
:branch_conflict
,
"You can not use same project/branch for source and target"
...
@@ -716,7 +703,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -716,7 +703,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
support_new_diff_notes?
def
support_new_diff_notes?
diff_
sha_refs
&&
diff_sha
_refs
.
complete?
diff_
refs
&&
diff
_refs
.
complete?
end
end
def
update_diff_notes_positions
(
old_diff_refs
:,
new_diff_refs
:)
def
update_diff_notes_positions
(
old_diff_refs
:,
new_diff_refs
:)
...
...
app/models/merge_request_diff.rb
View file @
49d63dc1
...
@@ -128,7 +128,7 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -128,7 +128,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
def
diff_refs
def
diff_refs
return
unless
start_commit
||
base_commit
return
unless
start_commit
_sha
||
base_commit_sha
Gitlab
::
Diff
::
DiffRefs
.
new
(
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
base_commit_sha
,
base_sha:
base_commit_sha
,
...
...
spec/models/merge_request_spec.rb
View file @
49d63dc1
...
@@ -723,7 +723,6 @@ describe MergeRequest, models: true do
...
@@ -723,7 +723,6 @@ describe MergeRequest, models: true do
end
end
end
end
<<<<<<<
HEAD
describe
'#branch_merge_base_commit'
do
describe
'#branch_merge_base_commit'
do
context
'source and target branch exist'
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
.
sha
).
to
eq
(
'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
)
}
...
@@ -737,8 +736,11 @@ describe MergeRequest, models: true do
...
@@ -737,8 +736,11 @@ describe MergeRequest, models: true do
it
'returns nil'
do
it
'returns nil'
do
expect
(
subject
.
branch_merge_base_commit
).
to
be_nil
expect
(
subject
.
branch_merge_base_commit
).
to
be_nil
=======
end
describe
"#diff_sha_refs"
do
end
end
describe
"#diff_refs"
do
context
"with diffs"
do
context
"with diffs"
do
subject
{
create
(
:merge_request
,
:with_diffs
)
}
subject
{
create
(
:merge_request
,
:with_diffs
)
}
...
@@ -747,7 +749,7 @@ describe MergeRequest, models: true do
...
@@ -747,7 +749,7 @@ describe MergeRequest, models: true do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:commit
)
expect_any_instance_of
(
Repository
).
not_to
receive
(
:commit
)
subject
.
diff_
sha_
refs
subject
.
diff_refs
end
end
it
"returns expected diff_refs"
do
it
"returns expected diff_refs"
do
...
@@ -757,8 +759,7 @@ describe MergeRequest, models: true do
...
@@ -757,8 +759,7 @@ describe MergeRequest, models: true do
head_sha:
subject
.
merge_request_diff
.
head_commit_sha
head_sha:
subject
.
merge_request_diff
.
head_commit_sha
)
)
expect
(
subject
.
diff_sha_refs
).
to
eq
(
expected_diff_refs
)
expect
(
subject
.
diff_refs
).
to
eq
(
expected_diff_refs
)
>>>>>>>
master
end
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