Commit 5a978e29 authored by tmaruyama's avatar tmaruyama

scm: git: raise exception if "git log" is error and block is given in lib revision method (#8857)

git-svn-id: https://svn.redmine.org/redmine/trunk@8837 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e2654892
...@@ -153,21 +153,25 @@ class Repository::Git < Repository ...@@ -153,21 +153,25 @@ class Repository::Git < Repository
from_scmid = nil from_scmid = nil
from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br] from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
h["branches"][br] ||= {} h["branches"][br] ||= {}
scm.revisions('', from_scmid, br, {:reverse => true}) do |rev| begin
db_rev = find_changeset_by_name(rev.revision) scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
transaction do db_rev = find_changeset_by_name(rev.revision)
if db_rev.nil? transaction do
db_saved_rev = save_revision(rev) if db_rev.nil?
parents = {} db_saved_rev = save_revision(rev)
parents[db_saved_rev] = rev.parents unless rev.parents.nil? parents = {}
parents.each do |ch, chparents| parents[db_saved_rev] = rev.parents unless rev.parents.nil?
ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact parents.each do |ch, chparents|
ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
end
end end
h["branches"][br]["last_scmid"] = rev.scmid
merge_extra_info(h)
self.save
end end
h["branches"][br]["last_scmid"] = rev.scmid
merge_extra_info(h)
self.save
end end
rescue Redmine::Scm::Adapters::CommandFailed => e
logger.error("save revisions error: #{e.message}")
end end
end end
end end
......
...@@ -290,8 +290,13 @@ module Redmine ...@@ -290,8 +290,13 @@ module Redmine
end end
revs revs
rescue ScmCommandAborted => e rescue ScmCommandAborted => e
logger.error("git log #{from_to.to_s} error: #{e.message}") err_msg = "git log error: #{e.message}"
revs logger.error(err_msg)
if block_given?
raise CommandFailed, err_msg
else
revs
end
end end
def diff(path, identifier_from, identifier_to=nil) def diff(path, identifier_from, identifier_to=nil)
......
...@@ -191,14 +191,16 @@ begin ...@@ -191,14 +191,16 @@ begin
end end
def test_revisions_invalid_rev def test_revisions_invalid_rev
revs1 = [] assert_equal [], @adapter.revisions('', '1234abcd', "master")
@adapter.revisions('', assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
@adapter.revisions('',
'1234abcd', '1234abcd',
"master", "master",
{:reverse => true}) do |rev| {:reverse => true}) do |rev|
revs1 << rev revs1 << rev
end
end end
assert_equal [], revs1
end end
def test_revisions_includes_master_two_revs def test_revisions_includes_master_two_revs
...@@ -277,14 +279,20 @@ begin ...@@ -277,14 +279,20 @@ begin
end end
def test_revisions_invalid_rev_excludes def test_revisions_invalid_rev_excludes
revs1 = [] assert_equal [],
@adapter.revisions('', nil, nil, @adapter.revisions('', nil, nil,
{:reverse => true, {:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']}) do |rev| :excludes => ['0123abcd4567']})
revs1 << rev assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
@adapter.revisions('', nil, nil,
{:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']}) do |rev|
revs1 << rev
end
end end
assert_equal [], revs1
end end
def test_getting_revisions_with_spaces_in_filename def test_getting_revisions_with_spaces_in_filename
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment