lib/braid/operations.rb in realityforge-braid-0.9.4 vs lib/braid/operations.rb in realityforge-braid-0.9.5
- old
+ new
@@ -1,7 +1,12 @@
require 'singleton'
require 'rubygems'
+if defined?(JRUBY_VERSION) || Gem.win_platform?
+ require'open3'
+else
+ require 'open4'
+end
require defined?(JRUBY_VERSION) ? 'open3' : 'open4'
require 'tempfile'
module Braid
module Operations
@@ -101,18 +106,19 @@
previous_lang = ENV['LANG']
ENV['LANG'] = 'C'
out, err = nil
+ status, pid = 0
log(cmd)
- if defined?(JRUBY_VERSION)
- Open3.popen3(cmd) do |stdin, stdout, stderr|
+ if defined?(JRUBY_VERSION) || Gem.win_platform?
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
out = stdout.read
err = stderr.read
+ status = wait_thr.value # Process::Status object returned.
end
- status = $?.exitstatus
else
status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
out = stdout.read
err = stderr.read
end.exitstatus
@@ -174,11 +180,11 @@
end
def fetch(remote = nil, *args)
args.unshift "-n #{remote}" if remote
# open4 messes with the pipes of index-pack
- sh("git fetch #{args.join(' ')} 2>&1 >/dev/null")
+ sh("git fetch #{args.join(' ')} 2>&1 > #{Gem.win_platform? ? 'nul' : '/dev/null'}")
end
def checkout(treeish)
invoke(:checkout, treeish)
true
@@ -282,20 +288,22 @@
status, out, err = exec!("git branch | grep '*'")
out[2..-1]
end
def apply(diff, *args)
- err = nil
+ status, err = nil, nil
- if defined?(JRUBY_VERSION)
- Open3.popen3("git apply --index --whitespace=nowarn #{args.join(' ')} -") do |stdin, stdout, stderr|
+ command = "git apply --index --whitespace=nowarn #{args.join(' ')} -"
+
+ if defined?(JRUBY_VERSION) || Gem.win_platform?
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stdin.puts(diff)
stdin.close
err = stderr.read
+ status = wait_thr.value # Process::Status object returned.
end
- status = $?.exitstatus
else
- status = Open4.popen4("git apply --index --whitespace=nowarn #{args.join(' ')} -") do |pid, stdin, stdout, stderr|
+ status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
stdin.puts(diff)
stdin.close
err = stderr.read
end.exitstatus
end