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
Boxiang Sun
gitlab-ce
Commits
7ba7fa50
Commit
7ba7fa50
authored
Oct 30, 2017
by
AlexWayfer
Committed by
Douwe Maan
Oct 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 500 error for old (somewhat) MRs
parent
b5d47d87
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
3 deletions
+47
-3
changelogs/unreleased/fix-500-on-old-merge-requests.yml
changelogs/unreleased/fix-500-on-old-merge-requests.yml
+5
-0
lib/gitlab/diff/position.rb
lib/gitlab/diff/position.rb
+5
-3
spec/lib/gitlab/diff/position_spec.rb
spec/lib/gitlab/diff/position_spec.rb
+37
-0
No files found.
changelogs/unreleased/fix-500-on-old-merge-requests.yml
0 → 100644
View file @
7ba7fa50
---
title
:
Fix 500 errors caused by empty diffs in some discussions
merge_request
:
14945
author
:
Alexander Popov
type
:
fixed
lib/gitlab/diff/position.rb
View file @
7ba7fa50
...
@@ -94,7 +94,9 @@ module Gitlab
...
@@ -94,7 +94,9 @@ module Gitlab
end
end
def
diff_file
(
repository
)
def
diff_file
(
repository
)
@diff_file
||=
begin
return
@diff_file
if
defined?
(
@diff_file
)
@diff_file
=
begin
if
RequestStore
.
active?
if
RequestStore
.
active?
key
=
{
key
=
{
project_id:
repository
.
project
.
id
,
project_id:
repository
.
project
.
id
,
...
@@ -122,8 +124,8 @@ module Gitlab
...
@@ -122,8 +124,8 @@ module Gitlab
def
find_diff_file
(
repository
)
def
find_diff_file
(
repository
)
return
unless
diff_refs
.
complete?
return
unless
diff_refs
.
complete?
return
unless
comparison
=
diff_refs
.
compare_in
(
repository
.
project
)
diff_refs
.
compare_in
(
repository
.
project
)
.
diffs
(
paths:
paths
,
expanded:
true
).
diff_files
.
first
comparison
.
diffs
(
paths:
paths
,
expanded:
true
).
diff_files
.
first
end
end
def
get_formatter_class
(
type
)
def
get_formatter_class
(
type
)
...
...
spec/lib/gitlab/diff/position_spec.rb
View file @
7ba7fa50
...
@@ -364,6 +364,43 @@ describe Gitlab::Diff::Position do
...
@@ -364,6 +364,43 @@ describe Gitlab::Diff::Position do
end
end
end
end
describe
"position for a missing ref"
do
let
(
:diff_refs
)
do
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
"not_existing_sha"
,
head_sha:
"existing_sha"
)
end
subject
do
described_class
.
new
(
old_path:
"files/ruby/feature.rb"
,
new_path:
"files/ruby/feature.rb"
,
old_line:
3
,
new_line:
nil
,
diff_refs:
diff_refs
)
end
describe
"#diff_file"
do
it
"does not raise exception"
do
expect
{
subject
.
diff_file
(
project
.
repository
)
}.
not_to
raise_error
end
end
describe
"#diff_line"
do
it
"does not raise exception"
do
expect
{
subject
.
diff_line
(
project
.
repository
)
}.
not_to
raise_error
end
end
describe
"#line_code"
do
it
"does not raise exception"
do
expect
{
subject
.
line_code
(
project
.
repository
)
}.
not_to
raise_error
end
end
end
describe
"position for a file in the initial commit"
do
describe
"position for a file in the initial commit"
do
let
(
:commit
)
{
project
.
commit
(
"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
)
}
let
(
:commit
)
{
project
.
commit
(
"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
)
}
...
...
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