Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use Open4 to check status of executed commands. Only raise exceptions…

… when status is non-zero.
  • Loading branch information...
commit 8e8e06e1b0e9a12fc29fc0692ae6f86d769a8a79 1 parent f600a01
@isabanin authored
View
2  Gemfile
@@ -1,5 +1,7 @@
source "http://rubygems.org"
+gem "open4", "~>1.3.0"
+
group :development do
gem "minitest", ">= 0"
gem "bundler", "~> 1.0.0"
View
2  Gemfile.lock
@@ -11,6 +11,7 @@ GEM
rbx-require-relative (> 0.0.4)
minitest (2.3.1)
mocha (0.9.12)
+ open4 (1.3.0)
rake (0.9.2)
rbx-require-relative (0.0.5)
rcov (0.9.9)
@@ -28,5 +29,6 @@ DEPENDENCIES
jeweler (~> 1.6.4)
minitest
mocha (~> 0.9)
+ open4 (~> 1.3.0)
rcov
ruby-debug (~> 0.10)
View
2  VERSION
@@ -1 +1 @@
-0.7.0
+0.7.1
View
2  lib/mercurial-ruby.rb
@@ -4,7 +4,7 @@
#
module Mercurial
- VERSION = '0.7.0'
+ VERSION = '0.7.1'
class Error < RuntimeError; end
View
12 lib/mercurial-ruby/command.rb
@@ -1,5 +1,6 @@
require 'timeout'
require 'digest/md5'
+require 'open4'
module Mercurial
class CommandError < Error; end
@@ -51,8 +52,8 @@ def execute_without_caching
def execution_proc
Proc.new do
debug(command)
- result, error = '', ''
- Open3.popen3(command) do |_, stdout, stderr|
+ result, error, = '', ''
+ status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
Timeout.timeout(timeout) do
while tmp = stdout.read(102400)
result += tmp
@@ -63,12 +64,13 @@ def execution_proc
error += tmp
end
end
- raise_error_if_needed(error)
+ raise_error_if_needed(status, error)
result
end
end
- def raise_error_if_needed(error)
+ def raise_error_if_needed(status, error)
+ return if status.exitstatus == 0
if error && error != ''
raise CommandError, error
end
@@ -81,7 +83,7 @@ def cache_key
def debug(msg)
if Mercurial.configuration.debug_mode
puts msg
- end
+ end
end
end
View
7 mercurial-ruby.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{mercurial-ruby}
- s.version = "0.7.0"
+ s.version = "0.7.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ilya Sabanin"]
- s.date = %q{2012-03-02}
+ s.date = %q{2012-03-05}
s.description = %q{Ruby API for Mercurial DVCS.}
s.email = %q{ilya.sabanin@gmail.com}
s.extra_rdoc_files = [
@@ -92,6 +92,7 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<open4>, ["~> 1.3.0"])
s.add_development_dependency(%q<minitest>, [">= 0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -99,6 +100,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<mocha>, ["~> 0.9"])
s.add_development_dependency(%q<ruby-debug>, ["~> 0.10"])
else
+ s.add_dependency(%q<open4>, ["~> 1.3.0"])
s.add_dependency(%q<minitest>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -107,6 +109,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<ruby-debug>, ["~> 0.10"])
end
else
+ s.add_dependency(%q<open4>, ["~> 1.3.0"])
s.add_dependency(%q<minitest>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
View
10 test/test_command.rb
@@ -16,6 +16,16 @@
Mercurial::Command.new("cd #{ @repository.path } && hg shikaka").execute
}.must_raise Mercurial::CommandError
end
+
+ it "should not translate exit status of zero with shell errors to ruby exceptions" do
+ Mercurial::Command.new("echo stderr >&2 && echo stdout && exit 0").execute.strip.must_equal "stdout"
+ end
+
+ it "should translate exit status of non-zero with shell errors to ruby exceptions" do
+ lambda{
+ Mercurial::Command.new("echo stderr >&2 && echo stdout && exit 1").execute
+ }.must_raise Mercurial::CommandError
+ end
it "should execute commands with timeout" do
Mercurial.configuration.stubs(:shell_timeout).returns(1)
Please sign in to comment.
Something went wrong with that request. Please try again.