From acbcdca1b9c811e374a8a769129dfc6ea21603c6 Mon Sep 17 00:00:00 2001 From: Colby Swandale Date: Mon, 8 Apr 2019 23:33:19 +1000 Subject: port sh_with_status from master --- lib/bundler/gem_helper.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 55f484f723..4675cce1a9 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -87,7 +87,7 @@ module Bundler def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem" - out, _ = sh_with_code("#{gem} install '#{built_gem_path}'#{" --local" if local}") + out, _ = sh_with_status("#{gem} install '#{built_gem_path}'#{" --local" if local}") raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/] Bundler.ui.confirm "#{name} (#{version}) installed." end @@ -129,7 +129,7 @@ module Bundler def perform_git_push(options = "") cmd = "git push #{options}" - out, code = sh_with_code(cmd) + out, code = sh_with_status(cmd) raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0 end @@ -144,11 +144,11 @@ module Bundler end def clean? - sh_with_code("git diff --exit-code")[1] == 0 + sh_with_status("git diff --exit-code")[1] == 0 end def committed? - sh_with_code("git diff-index --quiet --cached HEAD")[1] == 0 + sh_with_status("git diff-index --quiet --cached HEAD")[1] == 0 end def tag_version @@ -157,7 +157,7 @@ module Bundler yield if block_given? rescue RuntimeError Bundler.ui.error "Untagging #{version_tag} due to error." - sh_with_code "git tag -d #{version_tag}" + sh_with_status "git tag -d #{version_tag}" raise end @@ -174,21 +174,20 @@ module Bundler end def sh(cmd, &block) - out, code = sh_with_code(cmd, &block) - unless code.zero? + out, status = sh_with_status(cmd, &block) + unless status.success? + cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin) raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out) end out end - def sh_with_code(cmd, &block) - cmd += " 2>&1" - outbuf = String.new + def sh_with_status(cmd, &block) Bundler.ui.debug(cmd) SharedHelpers.chdir(base) do - outbuf = `#{cmd}` - status = $?.exitstatus - block.call(outbuf) if status.zero? && block + outbuf = IO.popen(cmd, :err => [:child, :out], &:read) + status = $? + block.call(outbuf) if status.success? && block [outbuf, status] end end -- cgit v1.2.1