兼容ruby 1.9

sw_new_course
guange 10 years ago
parent 2f86874c6c
commit 8da9805bcc

@ -19,15 +19,26 @@ module Grack
# _Not_ the same as `IO.popen(...).read`
# By using a block we tell IO.popen to close (wait for) the child process
# after we are done reading its output.
if RUBY_VERSION.start_with?("2")
IO.popen(popen_env, cmd, popen_options) { |p| p.read }
else
IO.popen(cmd, popen_options) { |p| p.read }
end
end
def execute(cmd)
cmd = command(cmd)
if block_given?
if RUBY_VERSION.start_with?("2")
IO.popen(popen_env, cmd, File::RDWR, popen_options) do |pipe|
yield(pipe)
end
else
IO.popen(cmd, File::RDWR, popen_options) do |pipe|
yield(pipe)
end
end
else
capture(cmd).chomp
end
@ -61,10 +72,12 @@ module Grack
match = execute(%W(rev-parse --git-dir)).match(/\.$|\.git$/)
if RUBY_VERSION.start_with?("2")
if match.to_s == '.git'
# Since the parent could be a git repo, we want to make sure the actual repo contains a git dir.
return false unless Dir.entries(repo).include?('.git')
end
end
match
end

Loading…
Cancel
Save