Fixes nil error when svn binary version is unknown (#1607).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1652 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-07-12 09:06:19 +00:00
parent 9ff53f97ee
commit 622b6121f4
4 changed files with 18 additions and 9 deletions

View File

@ -26,15 +26,24 @@ module Redmine
class AbstractAdapter #:nodoc: class AbstractAdapter #:nodoc:
class << self class << self
# Returns the version of the scm client # Returns the version of the scm client
# Eg: [1, 5, 0] # Eg: [1, 5, 0] or [] if unknown
def client_version def client_version
'Unknown version' []
end end
# Returns the version string of the scm client # Returns the version string of the scm client
# Eg: '1.5.0' # Eg: '1.5.0' or 'Unknown version' if unknown
def client_version_string def client_version_string
client_version.is_a?(Array) ? client_version.join('.') : client_version.to_s v = client_version || 'Unknown version'
v.is_a?(Array) ? v.join('.') : v.to_s
end
# Returns true if the current client version is above
# or equals the given one
# If option is :unknown is set to true, it will return
# true if the client version is unknown
def client_version_above?(v, options={})
((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
end end
end end

View File

@ -30,7 +30,7 @@ module Redmine
class << self class << self
def client_version def client_version
@@client_version ||= (hgversion || 'Unknown version') @@client_version ||= (hgversion || [])
end end
def hgversion def hgversion
@ -52,7 +52,7 @@ module Redmine
end end
def template_path_for(version) def template_path_for(version)
if version.is_a?(String) or ((version <=> [0,9,5]) > 0) if ((version <=> [0,9,5]) > 0) || version.empty?
ver = "1.0" ver = "1.0"
else else
ver = "0.9.5" ver = "0.9.5"

View File

@ -28,7 +28,7 @@ module Redmine
class << self class << self
def client_version def client_version
@@client_version ||= (svn_binary_version || 'Unknown version') @@client_version ||= (svn_binary_version || [])
end end
def svn_binary_version def svn_binary_version
@ -109,7 +109,7 @@ module Redmine
def properties(path, identifier=nil) def properties(path, identifier=nil)
# proplist xml output supported in svn 1.5.0 and higher # proplist xml output supported in svn 1.5.0 and higher
return nil if (self.class.client_version <=> [1, 5, 0]) < 0 return nil unless self.class.client_version_above?([1, 5, 0])
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}" cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}"

View File

@ -25,7 +25,7 @@ begin
def test_template_path def test_template_path
to_test = { [0,9,5] => "0.9.5", to_test = { [0,9,5] => "0.9.5",
[1,0] => "1.0", [1,0] => "1.0",
"Unknown version" => "1.0", [] => "1.0",
[1,0,1] => "1.0"} [1,0,1] => "1.0"}
to_test.each do |v, template| to_test.each do |v, template|