summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/merge_request_diff.rb2
-rw-r--r--changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml5
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb17
-rw-r--r--spec/models/merge_request_diff_spec.rb8
4 files changed, 31 insertions, 1 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index 3d72c447b4b..a073bbfad20 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -182,7 +182,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
def diffs(diff_options = nil)
- if without_files? && comparison = diff_refs.compare_in(project)
+ if without_files? && comparison = diff_refs&.compare_in(project)
# It should fetch the repository when diffs are cleaned by the system.
# We don't keep these for storage overload purposes.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/37639
diff --git a/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml b/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml
new file mode 100644
index 00000000000..71a2d94fc55
--- /dev/null
+++ b/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml
@@ -0,0 +1,5 @@
+---
+title: Render MR page when diffs cannot be fetched from the database or the git repository
+merge_request: 20680
+author:
+type: fixed
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 444415011a9..1692f299552 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -53,6 +53,23 @@ describe Projects::MergeRequestsController do
it_behaves_like "loads labels", :show
describe 'as html' do
+ context 'when diff files were cleaned' do
+ render_views
+
+ it 'renders page when diff size is not persisted and diff_refs does not exist' do
+ diff = merge_request.merge_request_diff
+
+ diff.clean!
+ diff.update!(real_size: nil,
+ start_commit_sha: nil,
+ base_commit_sha: nil)
+
+ go(format: :html)
+
+ expect(response).to be_success
+ end
+ end
+
it "renders merge request page" do
go(format: :html)
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb
index ccc3ff861c5..0aee78ac12d 100644
--- a/spec/models/merge_request_diff_spec.rb
+++ b/spec/models/merge_request_diff_spec.rb
@@ -82,6 +82,14 @@ describe MergeRequestDiff do
diff.diffs
end
+
+ it 'returns persisted diffs if diff refs does not exist' do
+ expect(diff).to receive(:load_diffs)
+
+ diff.update!(start_commit_sha: nil, base_commit_sha: nil)
+
+ diff.diffs
+ end
end
end