Skip to content

Bug reporting fails when git repo has not been fetched #129

@JasonBarnabe

Description

@JasonBarnabe

project.repo.object(revision) throws when it can't find the commit (the commit happened after the last time the repo was fetched).

E, [2017-03-13T09:01:24.885656 #27338] ERROR -- : -- ERROR IN OccurrencesWorker 49810320 --
E, [2017-03-13T09:01:24.885739 #27338] ERROR -- : git cat-file "-t" "6e96b806e7ba214246c08bf2c32618af2b261df3"  2>&1:error: unable to find 6e96b806e7ba214246c08bf2c32618af2b261df3
fatal: git cat-file 6e96b806e7ba214246c08bf2c32618af2b261df3: bad file
E, [2017-03-13T09:01:24.886029 #27338] ERROR -- : /home/web/.rvm/gems/ruby-2.3.0@squash/bundler/gems/ruby-git-eeab421f5ca7/lib/git/lib.rb:724:in `command'
/home/web/.rvm/gems/ruby-2.3.0@squash/bundler/gems/ruby-git-eeab421f5ca7/lib/git/lib.rb:136:in `object_type'
/home/web/.rvm/gems/ruby-2.3.0@squash/bundler/gems/ruby-git-eeab421f5ca7/lib/git/object.rb:262:in `new'
/home/web/.rvm/gems/ruby-2.3.0@squash/bundler/gems/ruby-git-eeab421f5ca7/lib/git/base.rb:153:in `object'
/var/www/apps/squash_20170319/lib/blamer/recency.rb:61:in `resolve_revision'
/var/www/apps/squash_20170319/lib/workers/occurrences_worker.rb:189:in `set_deploy_and_commit'
/var/www/apps/squash_20170319/lib/workers/occurrences_worker.rb:77:in `perform'
/var/www/apps/squash_20170319/lib/workers/occurrences_worker.rb:45:in `perform'
/var/www/apps/squash_20170319/lib/background_runner/multithread.rb:31:in `block in run'
/var/www/apps/squash_20170319/lib/multithread.rb:64:in `spinoff'
/var/www/apps/squash_20170319/lib/background_runner/multithread.rb:31:in `run'
/var/www/apps/squash_20170319/lib/background_runner.rb:38:in `run'
/var/www/apps/squash_20170319/app/controllers/api/v1_controller.rb:63:in `notify'

The code seems to expect it to return nil, when in fact it raises an exception. The fix:

diff --git a/lib/blamer/recency.rb b/lib/blamer/recency.rb
index 23a211f..d5ef0e4 100644
--- a/lib/blamer/recency.rb
+++ b/lib/blamer/recency.rb
@@ -58,7 +58,12 @@ module Blamer
   class Recency < Base
 
     def self.resolve_revision(project, revision)
-      commit   = project.repo.object(revision)
+      begin
+        commit   = project.repo.object(revision)
+      rescue Git::GitExecuteError
+        # Try fetching
+        commit = nil
+      end
       if commit.nil?
         project.repo(&:fetch)
         commit = project.repo.object(revision)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions