Commit ab28ea07 authored by Annabel Dunstone Gray's avatar Annabel Dunstone Gray
Browse files

Merge branch '41491-fix-nil-blob-name-error' into 'master'

Fix 500 error when visiting a commit where the blobs do not exist (nil blobs)

Closes #41491

See merge request gitlab-org/gitlab-ce!16237
parents 4fc0a090 1faaf6ff
...@@ -651,12 +651,18 @@ ...@@ -651,12 +651,18 @@
min-width: 0; min-width: 0;
} }
.diff-changed-file-name { .diff-changed-file-name,
.diff-changed-blank-file-name {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.diff-changed-blank-file-name {
color: $gl-text-color-tertiary;
font-style: italic;
}
.diff-changed-file-path { .diff-changed-file-path {
color: $gl-text-color-tertiary; color: $gl-text-color-tertiary;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
- unless diff_file.submodule? - unless diff_file.submodule?
- blob = diff_file.blob - blob = diff_file.blob
.file-actions.hidden-xs .file-actions.hidden-xs
- if blob.readable_text? - if blob&.readable_text?
= link_to '#', class: 'js-toggle-diff-comments btn active has-tooltip', title: "Toggle comments for this file", disabled: @diff_notes_disabled do = link_to '#', class: 'js-toggle-diff-comments btn active has-tooltip', title: "Toggle comments for this file", disabled: @diff_notes_disabled do
= icon('comment') = icon('comment')
\ \
......
...@@ -24,7 +24,12 @@ ...@@ -24,7 +24,12 @@
%a.diff-changed-file{ href: "##{hexdigest(diff_file.file_path)}", title: diff_file.new_path } %a.diff-changed-file{ href: "##{hexdigest(diff_file.file_path)}", title: diff_file.new_path }
= sprite_icon(diff_file_changed_icon(diff_file), size: 16, css_class: "#{diff_file_changed_icon_color(diff_file)} diff-file-changed-icon append-right-8") = sprite_icon(diff_file_changed_icon(diff_file), size: 16, css_class: "#{diff_file_changed_icon_color(diff_file)} diff-file-changed-icon append-right-8")
%span.diff-changed-file-content.append-right-8 %span.diff-changed-file-content.append-right-8
%strong.diff-changed-file-name= diff_file.blob.name - if diff_file.blob&.name
%strong.diff-changed-file-name
= diff_file.blob.name
- else
%strong.diff-changed-blank-file-name
= s_('Diffs|No file name available')
%span.diff-changed-file-path.prepend-top-5= diff_file_path_text(diff_file) %span.diff-changed-file-path.prepend-top-5= diff_file_path_text(diff_file)
%span.diff-changed-stats %span.diff-changed-stats
%span.cgreen< %span.cgreen<
......
---
title: Fix 500 error when visiting a commit where the blobs do not exist
merge_request:
author:
type: fixed
require 'spec_helper' require 'spec_helper'
describe 'User broweses commits' do describe 'User browses commits' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project) { create(:project, :repository, namespace: user.namespace) }
...@@ -31,6 +31,19 @@ ...@@ -31,6 +31,19 @@
check_author_link(RepoHelpers.sample_commit.author_email, user) check_author_link(RepoHelpers.sample_commit.author_email, user)
end end
end end
context 'when the blob does not exist' do
let(:commit) { create(:commit, project: project) }
it 'shows a blank label' do
allow_any_instance_of(Gitlab::Diff::File).to receive(:blob).and_return(nil)
allow_any_instance_of(Gitlab::Diff::File).to receive(:raw_binary?).and_return(true)
visit(project_commit_path(project, commit))
expect(find('.diff-file-changes', visible: false)).to have_content('No file name available')
end
end
end end
private private
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment