]> source.dussan.org Git - redmine.git/commitdiff
scm: git: raise exception if "git log" is error and block is given in lib revision...
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 10 Feb 2012 22:56:54 +0000 (22:56 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 10 Feb 2012 22:56:54 +0000 (22:56 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8837 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/git.rb
lib/redmine/scm/adapters/git_adapter.rb
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb

index 7532bcd6a3d1121b975137669e351cb7a6ed8f9f..c5606f240f9228df0ac4b20eff6c5bdf4167d2ca 100644 (file)
@@ -153,21 +153,25 @@ class Repository::Git < Repository
       from_scmid = nil
       from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
       h["branches"][br] ||= {}
-      scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
-        db_rev = find_changeset_by_name(rev.revision)
-        transaction do
-          if db_rev.nil?
-            db_saved_rev = save_revision(rev)
-            parents = {}
-            parents[db_saved_rev] = rev.parents unless rev.parents.nil?
-            parents.each do |ch, chparents|
-              ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
+      begin
+        scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
+          db_rev = find_changeset_by_name(rev.revision)
+          transaction do
+            if db_rev.nil?
+              db_saved_rev = save_revision(rev)
+              parents = {}
+              parents[db_saved_rev] = rev.parents unless rev.parents.nil?
+              parents.each do |ch, chparents|
+                ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
+              end
             end
+            h["branches"][br]["last_scmid"] = rev.scmid
+            merge_extra_info(h)
+            self.save
           end
-          h["branches"][br]["last_scmid"] = rev.scmid
-          merge_extra_info(h)
-          self.save
         end
+      rescue Redmine::Scm::Adapters::CommandFailed => e
+        logger.error("save revisions error: #{e.message}")
       end
     end
   end
index d6c5544613c710b4bb464faf6bd77d5885be2730..9639b41f98a06710c2fbd150262ca4d20c051afd 100644 (file)
@@ -290,8 +290,13 @@ module Redmine
           end
           revs
         rescue ScmCommandAborted => e
-          logger.error("git log #{from_to.to_s} error: #{e.message}")
-          revs
+          err_msg = "git log error: #{e.message}"
+          logger.error(err_msg)
+          if block_given?
+            raise CommandFailed, err_msg
+          else
+            revs
+          end
         end
 
         def diff(path, identifier_from, identifier_to=nil)
index 51c2718c27680e796bdf98408c834d3772cf94a2..990070fbc315eab6fc7c17d7a41798ee8f8aee93 100644 (file)
@@ -191,14 +191,16 @@ begin
       end
 
       def test_revisions_invalid_rev
-        revs1 = []
-        @adapter.revisions('',
+        assert_equal [], @adapter.revisions('', '1234abcd', "master")
+        assert_raise Redmine::Scm::Adapters::CommandFailed do
+          revs1 = []
+          @adapter.revisions('',
                            '1234abcd',
                            "master",
                            {:reverse => true}) do |rev|
-          revs1 << rev
+            revs1 << rev
+          end
         end
-        assert_equal [], revs1
       end
 
       def test_revisions_includes_master_two_revs
@@ -277,14 +279,20 @@ begin
       end
 
       def test_revisions_invalid_rev_excludes
-        revs1 = []
-        @adapter.revisions('', nil, nil,
-                           {:reverse => true,
-                            :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
-                            :excludes => ['0123abcd4567']}) do |rev|
-          revs1 << rev
+        assert_equal [],
+                     @adapter.revisions('', nil, nil,
+                                        {:reverse => true,
+                                         :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+                                         :excludes => ['0123abcd4567']})
+        assert_raise Redmine::Scm::Adapters::CommandFailed do
+          revs1 = []
+          @adapter.revisions('', nil, nil,
+                             {:reverse => true,
+                              :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
+                              :excludes => ['0123abcd4567']}) do |rev|
+            revs1 << rev
+          end
         end
-        assert_equal [], revs1
       end
 
       def test_getting_revisions_with_spaces_in_filename