Skip to content

Commit 70a8371

Browse files
committed
Added better 1.8-compatibility, but only by re-adding some Dir.chdir calls.
1 parent 858ead4 commit 70a8371

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

lib/git/base.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,16 @@ def chdir # :yields: the Git::Path
118118
end
119119

120120
# returns the repository size in bytes
121-
def repo_size
122-
return IO.popen("du -s", {:chdir => repo.path}).read.chomp.split.first.to_i
121+
if (RUBY_VERSION.to_f < 1.9)
122+
def repo_size
123+
Dir.chdir(repo.path) do
124+
return IO.popen("du -s").read.chomp.split.first.to_i
125+
end
126+
end
127+
else
128+
def repo_size
129+
return IO.popen("du -s", {:chdir => repo.path}).read.chomp.split.first.to_i
130+
end
123131
end
124132

125133
#g.config('user.name', 'Scott Chacon') # sets value

lib/git/lib.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,16 +806,27 @@ def log_path_options(opts)
806806
arr_opts
807807
end
808808

809-
def run_command(git_cmd, chdir = nil, &block)
810-
commands = [git_cmd]
811-
commands << {:chdir => chdir} unless chdir.nil?
812-
if block_given?
813-
retval = IO.popen(*commands, &block)
814-
return retval, $?
809+
# run_command
810+
if (RUBY_VERSION.to_f < 1.9)
811+
# in Ruby 1.8 we just have to run inside Dir.chdir. No getting around it
812+
def run_command(git_cmd, chdir = nil, &block)
813+
Dir.chdir(chdir || Dir.getwd) do
814+
return IO.popen(git_cmd, &block), $? if block_given?
815+
return `#{git_cmd}`.chomp, $?
816+
end
815817
end
816-
out, process_status = Open3.capture2(*commands)
818+
else
819+
def run_command(git_cmd, chdir = nil, &block)
820+
commands = [git_cmd]
821+
commands << {:chdir => chdir} unless chdir.nil?
822+
if block_given?
823+
retval = IO.popen(*commands, &block)
824+
return retval, $?
825+
end
826+
out, process_status = Open3.capture2(*commands)
817827

818-
return out.chomp, process_status
828+
return out.chomp, process_status
829+
end
819830
end
820831

821832
def escape(s)

0 commit comments

Comments
 (0)