Skip to content

Commit d029e4c

Browse files
committed
Use Open3.capture3 instead of IO.popen
Signed-off-by: James Couball <jcouball@yahoo.com>
1 parent 4231e94 commit d029e4c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/git/base.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,25 @@ def self.root_of_worktree(working_dir)
7272

7373
# Option 1 using IO.popen
7474
#
75-
# IO.popen(git_cmd, :chdir => working_dir) do |io|
75+
# IO.popen(git_cmd, chdir: working_dir) do |io|
7676
# status = Process.wait2(io.pid).last
7777
# result = io.read.chomp
7878
# end
7979

8080
# Option 2 using Open3.popen2
8181
#
82-
Open3.popen2(git_cmd, chdir: working_dir) do |stdin, stdout, wait_thr|
83-
status = wait_thr.value
84-
result = stdout.chomp
85-
end
82+
# Open3.popen2(git_cmd, chdir: working_dir) do |stdin, stdout, wait_thr|
83+
# status = wait_thr.value
84+
# result = stdout.read.chomp
85+
# end
8686

8787
# Option 3 using Open3.capture3
8888
#
89-
# stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts)
90-
# result = status_s
89+
stdout_s, stderr_s, status = Open3.capture3(git_cmd, chdir: working_dir)
90+
result = stdout_s
9191

9292
raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success?
93+
9394
result
9495
end
9596

lib/git/lib.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,14 @@ def run_command(git_cmd, chdir=nil, &block)
12611261

12621262
# Option 2 using Open3.popen2
12631263
#
1264-
Open3.popen2(custom_git_env_variables, git_cmd, opts) do |stdin, stdout, wait_thr|
1265-
[block.call(stdout), wait_thr.value]
1266-
end
1264+
# Open3.popen2(custom_git_env_variables, git_cmd, opts) do |stdin, stdout, wait_thr|
1265+
# [block.call(stdout), wait_thr.value]
1266+
# end
12671267

12681268
# Option 3 using Open3.capture3
12691269
#
1270-
# stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts)
1271-
# [block.call(StringIO.new(stdout_s)), status]
1270+
stdout_s, stderr_s, status = Open3.capture3(custom_git_env_variables, git_cmd, opts)
1271+
[block.call(StringIO.new(stdout_s)), status]
12721272
end
12731273

12741274
def escape(s)

0 commit comments

Comments
 (0)