diff --git a/lib/git/base.rb b/lib/git/base.rb index 3f7d3c9e..1b826ccb 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -72,24 +72,25 @@ def self.root_of_worktree(working_dir) # Option 1 using IO.popen # - # IO.popen(git_cmd, :chdir => working_dir) do |io| + # IO.popen(git_cmd, chdir: working_dir) do |io| # status = Process.wait2(io.pid).last # result = io.read.chomp # end # Option 2 using Open3.popen2 # - Open3.popen2(git_cmd, chdir: working_dir) do |stdin, stdout, wait_thr| - status = wait_thr.value - result = stdout.chomp - end + # Open3.popen2(git_cmd, chdir: working_dir) do |stdin, stdout, wait_thr| + # status = wait_thr.value + # result = stdout.read.chomp + # end # Option 3 using Open3.capture3 # - # stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts) - # result = status_s + stdout_s, stderr_s, status = Open3.capture3(git_cmd, chdir: working_dir) + result = stdout_s.chomp raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success? + result end diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 2a1f1ded..453776c6 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -3,6 +3,7 @@ require 'tempfile' require 'zlib' require 'open3' +require 'stringio' module Git class Lib @@ -1261,14 +1262,14 @@ def run_command(git_cmd, chdir=nil, &block) # Option 2 using Open3.popen2 # - Open3.popen2(custom_git_env_variables, git_cmd, opts) do |stdin, stdout, wait_thr| - [block.call(stdout), wait_thr.value] - end + # Open3.popen2(custom_git_env_variables, git_cmd, opts) do |stdin, stdout, wait_thr| + # [block.call(stdout), wait_thr.value] + # end # Option 3 using Open3.capture3 # - # stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts) - # [block.call(StringIO.new(stdout_s)), status] + stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts) + [block.call(StringIO.new(stdout_s)), status] end def escape(s)