diff --git a/.travis.yml b/.travis.yml index b2ea18fc..57d5041a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: ruby rvm: - - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.1 diff --git a/git.gemspec b/git.gemspec index 5e90626e..be398103 100644 --- a/git.gemspec +++ b/git.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.version = '1.3.0' s.require_paths = ['lib'] - s.required_ruby_version = '>= 1.9' + s.required_ruby_version = '>= 1.9.3' s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.requirements = ['git 1.6.0.0, or greater'] diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 777e42ea..f95452a4 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -859,13 +859,28 @@ def meets_required_version? def command_lines(cmd, opts = [], chdir = true, redirect = '') cmd_op = command(cmd, opts, chdir) - op = cmd_op.encode("UTF-8", "binary", { - :invalid => :replace, - :undef => :replace - }) - op.split("\n") + split_utf8(cmd_op) end + def split_utf8(s) + # ruby can think the string is utf8 but any action on the strings chars + # will trigger errors. Here we try to split utf8 strings. + # It it isn't utf8 or if it fails, we fallback to assume the input is + # "binary" encoding + result = begin + s.encoding == Encoding::UTF_8 && s.split("\n") + rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError + nil + end + + result ||= s.encode("UTF-8", "binary", { + :invalid => :replace, + :undef => :replace, + }).split("\n") + result + end + + # Takes the current git's system ENV variables and store them. def store_git_system_env_variables @git_system_env_variables = {}