Skip to content
Snippets Groups Projects
Commit f49df490 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin :two:
Browse files

Handle exception for binary files blame

Contributes to #385899

**Problem**

Server returns a 500 error when user tries to blame a binary file.

**Solution**

Redirect user to blob view with an error message.

Changelog: fixed
parent 8cc148cd
No related branches found
No related tags found
1 merge request!121530Handle exception for binary files blame
......@@ -9,6 +9,7 @@ class Projects::BlameController < Projects::ApplicationController
before_action :assign_ref_vars
before_action :authorize_read_code!
before_action :load_blob
before_action :require_non_binary_blob
feature_category :source_code_management
urgency :low, [:show]
......@@ -40,6 +41,10 @@ def load_blob
redirect_to_tree_root_for_missing_path(@project, @ref, @path)
end
def require_non_binary_blob
redirect_to project_blob_path(@project, File.join(@ref, @path)), notice: _('Blame for binary files is not supported.') if @blob.binary?
end
def load_environment
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
environment_params[:find_latest] = true
......
......@@ -10,7 +10,16 @@ description: "Documentation on Git file blame."
[Git blame](https://git-scm.com/docs/git-blame) provides more information
about every line in a file, including the last modified time, author, and
commit hash. To view it for a file:
commit hash.
## View blame for a file
Prerequisites:
- The file type must be text-based. The GitLab UI does not display
`git blame` results for binary files.
To view the blame for a file:
1. Go to your project's **Repository > Files**.
1. Select the file you want to review.
......
......@@ -7408,6 +7408,9 @@ msgstr ""
msgid "Blame could not be loaded as a single page."
msgstr ""
 
msgid "Blame for binary files is not supported."
msgstr ""
msgid "BlobViewer|View on %{environmentName}"
msgstr ""
 
......@@ -28,6 +28,14 @@
end
end
context 'valid branch, binary file' do
let(:id) { 'master/files/images/logo-black.png' }
it 'redirects' do
expect(subject).to redirect_to("/#{project.full_path}/-/blob/master/files/images/logo-black.png")
end
end
context 'invalid branch, valid file' do
let(:id) { 'invalid-branch/files/ruby/missing_file.rb' }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment