Commit 85ec34518318cf40f2a0c5ef60398e0225e691c1
1 parent
26befdc7
Exists in
master
and in
4 other branches
Prevent 500 error on git blame if empty file
Showing
3 changed files
with
4 additions
and
3 deletions
Show diff stats
app/assets/stylesheets/sections/tree.scss
app/views/blob/_actions.html.haml
| @@ -8,5 +8,5 @@ | @@ -8,5 +8,5 @@ | ||
| 8 | - if current_page? project_blame_path(@project, @id) | 8 | - if current_page? project_blame_path(@project, @id) |
| 9 | = link_to "normal view", project_blob_path(@project, @id), class: "btn btn-tiny" | 9 | = link_to "normal view", project_blob_path(@project, @id), class: "btn btn-tiny" |
| 10 | - else | 10 | - else |
| 11 | - = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" | 11 | + = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" unless @blob.empty? |
| 12 | = link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny" | 12 | = link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny" |
lib/gitlab/git/blame.rb
| @@ -6,13 +6,14 @@ module Gitlab | @@ -6,13 +6,14 @@ module Gitlab | ||
| 6 | 6 | ||
| 7 | def initialize(repository, sha, path) | 7 | def initialize(repository, sha, path) |
| 8 | @repository, @sha, @path = repository, sha, path | 8 | @repository, @sha, @path = repository, sha, path |
| 9 | - | ||
| 10 | end | 9 | end |
| 11 | 10 | ||
| 12 | def each | 11 | def each |
| 13 | raw_blame = Grit::Blob.blame(repository.repo, sha, path) | 12 | raw_blame = Grit::Blob.blame(repository.repo, sha, path) |
| 14 | 13 | ||
| 15 | raw_blame.each do |commit, lines| | 14 | raw_blame.each do |commit, lines| |
| 15 | + next unless commit | ||
| 16 | + | ||
| 16 | commit = Gitlab::Git::Commit.new(commit) | 17 | commit = Gitlab::Git::Commit.new(commit) |
| 17 | yield(commit, lines) | 18 | yield(commit, lines) |
| 18 | end | 19 | end |