Commit 85ec34518318cf40f2a0c5ef60398e0225e691c1

Authored by Dmitriy Zaporozhets
1 parent 26befdc7

Prevent 500 error on git blame if empty file

app/assets/stylesheets/sections/tree.scss
@@ -97,7 +97,7 @@ @@ -97,7 +97,7 @@
97 97
98 .tree-btn-group { 98 .tree-btn-group {
99 .btn { 99 .btn {
100 - margin-right:-3px; 100 + margin-right: 0px;
101 padding: 2px 10px; 101 padding: 2px 10px;
102 } 102 }
103 } 103 }
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