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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
de8497ca
Commit
de8497ca
authored
Sep 18, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Error 500 when comparing non-existing branches
Closes #2593
parent
ac571623
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
5 deletions
+36
-5
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+6
-4
app/services/compare_service.rb
app/services/compare_service.rb
+4
-1
spec/controllers/projects/compare_controller_spec.rb
spec/controllers/projects/compare_controller_spec.rb
+26
-0
No files found.
app/controllers/projects/compare_controller.rb
View file @
de8497ca
...
...
@@ -16,11 +16,13 @@ class Projects::CompareController < Projects::ApplicationController
compare_result
=
CompareService
.
new
.
execute
(
@project
,
head_ref
,
@project
,
base_ref
)
if
compare_result
@commits
=
compare_result
.
commits
@diffs
=
compare_result
.
diffs
@commit
=
@commits
.
last
@line_notes
=
[]
end
end
def
create
redirect_to
namespace_project_compare_path
(
@project
.
namespace
,
@project
,
...
...
app/services/compare_service.rb
View file @
de8497ca
...
...
@@ -4,7 +4,10 @@ require 'securerandom'
# and return Gitlab::CompareResult object that responds to commits and diffs
class
CompareService
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
)
source_sha
=
source_project
.
commit
(
source_branch
).
sha
source_commit
=
source_project
.
commit
(
source_branch
)
return
unless
source_commit
source_sha
=
source_commit
.
sha
# If compare with other project we need to fetch ref first
unless
target_project
==
source_project
...
...
spec/controllers/projects/compare_controller_spec.rb
View file @
de8497ca
...
...
@@ -22,4 +22,30 @@ describe Projects::CompareController do
expect
(
assigns
(
:diffs
).
length
).
to
be
>=
1
expect
(
assigns
(
:commits
).
length
).
to
be
>=
1
end
describe
'non-existent refs'
do
it
'invalid source ref'
do
get
(
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
from:
'non-existent'
,
to:
ref_to
)
expect
(
response
).
to
be_success
expect
(
assigns
(
:diffs
)).
to
eq
([])
expect
(
assigns
(
:commits
)).
to
eq
([])
end
it
'invalid target ref'
do
get
(
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
from:
ref_from
,
to:
'non-existent'
)
expect
(
response
).
to
be_success
expect
(
assigns
(
:diffs
)).
to
eq
(
nil
)
expect
(
assigns
(
:commits
)).
to
eq
(
nil
)
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