Skip to content

Commit

Permalink
Merge pull request isabanin#1 from potatosalad/master
Browse files Browse the repository at this point in the history
Ignore mercurial warnings printed to stderr as long as the exitstatus is 0.
  • Loading branch information
isabanin committed Feb 23, 2012
2 parents 809f6dd + 6d213bb commit f0be28c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/mercurial-ruby/command.rb
Expand Up @@ -47,8 +47,8 @@ def execute_without_caching
def execution_proc
Proc.new do
debug(command)
result, error = '', ''
Open3.popen3(command) do |_, stdout, stderr|
result, error, status = '', '', nil
Open3.popen3(command) do |_, stdout, stderr, wait_thr|
Timeout.timeout(timeout) do
while tmp = stdout.read(102400)
result += tmp
Expand All @@ -58,14 +58,15 @@ def execution_proc
while tmp = stderr.read(1024)
error += tmp
end
status = wait_thr.value
end
raise_error_if_needed(error)
raise_error_if_needed(error, status)
result
end
end

def raise_error_if_needed(error)
if error && error != ''
def raise_error_if_needed(error, status = nil)
if (status.nil? || status.exitstatus != 0) && error && error != ''
raise CommandError, error
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_command.rb
Expand Up @@ -16,6 +16,18 @@
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
lambda{
Mercurial::Command.new("echo stderr >&2 && echo stdout && exit 0").execute
}.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)
Expand Down

0 comments on commit f0be28c

Please sign in to comment.