diff --git a/.travis.yml b/.travis.yml index cc1f5246..7dc0cc27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ rvm: - 1.9.2 - 1.9.3 - 2.0.0 - - 2.1 + - 2.1.1 + - 2.1.2 - jruby-18mode - jruby-19mode - ree diff --git a/lib/git/lib.rb b/lib/git/lib.rb index f1bd6439..03b19995 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -739,31 +739,29 @@ def command(cmd, opts = [], chdir = true, redirect = '', &block) ENV['GIT_INDEX_FILE'] = @git_index_file path = @git_work_dir || @git_dir || @path - + opts = [opts].flatten.map {|s| escape(s) }.join(' ') git_cmd = "git #{cmd} #{opts} #{redirect} 2>&1" - out = nil + output = nil + if chdir && (Dir.getwd != path) - Dir.chdir(path) { out = run_command(git_cmd, &block) } + Dir.chdir(path) { output = run_command(git_cmd, &block) } else - - out = run_command(git_cmd, &block) + output = run_command(git_cmd, &block) end if @logger @logger.info(git_cmd) - @logger.debug(out) + @logger.debug(output) end - if $?.exitstatus > 0 - if $?.exitstatus == 1 && out == '' - return '' - end - raise Git::GitExecuteError.new(git_cmd + ':' + out.to_s) + if $?.exitstatus > 1 || ($?.exitstatus == 1 && output != '') + raise Git::GitExecuteError.new(git_cmd + ':' + output.to_s) end - out + + return output end # Takes the diff command line output (as Array) and parse it into a Hash @@ -821,11 +819,9 @@ def log_path_options(opts) end def run_command(git_cmd, &block) - if block_given? - IO.popen(git_cmd, &block) - else - `#{git_cmd}`.chomp - end + return IO.popen(git_cmd, &block) if block_given? + + `#{git_cmd}`.chomp end def escape(s) diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb index 89aeb459..fd47e609 100644 --- a/tests/units/test_index_ops.rb +++ b/tests/units/test_index_ops.rb @@ -94,9 +94,9 @@ def test_revert g.commit("second-commit") g.gcommit('HEAD') - commits = g.log(1e4).count + commits = g.log(10000).count g.revert(first_commit.sha) - assert_equal(commits + 1, g.log(1e4).count) + assert_equal(commits + 1, g.log(10000).count) assert(!File.exist?('test-file2')) end end