From 85ec34518318cf40f2a0c5ef60398e0225e691c1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 18 Apr 2013 12:46:41 +0300 Subject: [PATCH] Prevent 500 error on git blame if empty file --- app/assets/stylesheets/sections/tree.scss | 2 +- app/views/blob/_actions.html.haml | 2 +- lib/gitlab/git/blame.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss index def440c71..ffde6aa3f 100644 --- a/app/assets/stylesheets/sections/tree.scss +++ b/app/assets/stylesheets/sections/tree.scss @@ -97,7 +97,7 @@ .tree-btn-group { .btn { - margin-right:-3px; + margin-right: 0px; padding: 2px 10px; } } diff --git a/app/views/blob/_actions.html.haml b/app/views/blob/_actions.html.haml index 1da39e72c..456c7432c 100644 --- a/app/views/blob/_actions.html.haml +++ b/app/views/blob/_actions.html.haml @@ -8,5 +8,5 @@ - if current_page? project_blame_path(@project, @id) = link_to "normal view", project_blob_path(@project, @id), class: "btn btn-tiny" - else - = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" + = link_to "blame", project_blame_path(@project, @id), class: "btn btn-tiny" unless @blob.empty? = link_to "history", project_commits_path(@project, @id), class: "btn btn-tiny" diff --git a/lib/gitlab/git/blame.rb b/lib/gitlab/git/blame.rb index d6e988b67..d7282c587 100644 --- a/lib/gitlab/git/blame.rb +++ b/lib/gitlab/git/blame.rb @@ -6,13 +6,14 @@ module Gitlab def initialize(repository, sha, path) @repository, @sha, @path = repository, sha, path - end def each raw_blame = Grit::Blob.blame(repository.repo, sha, path) raw_blame.each do |commit, lines| + next unless commit + commit = Gitlab::Git::Commit.new(commit) yield(commit, lines) end -- 2.11.0