gitlab-org--gitlab-foss/lib/gitlab/git/popen.rb
Alejandro Rodríguez 34eeac6108 Use Gitlab::Git's Popen on that module's code
This allows the current Gitaly migration to depend on less code outside
of the Gitlab::Git module
2017-09-20 13:21:54 +02:00

32 lines
727 B
Ruby

# Gitaly note: JV: no RPC's here.
require 'open3'
module Gitlab
module Git
module Popen
def popen(cmd, path, vars = {})
unless cmd.is_a?(Array)
raise "System commands must be given as an array of strings"
end
path ||= Dir.pwd
vars['PWD'] = path
options = { chdir: path }
@cmd_output = ""
@cmd_status = 0
Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|
yield(stdin) if block_given?
stdin.close
@cmd_output << stdout.read
@cmd_output << stderr.read
@cmd_status = wait_thr.value.exitstatus
end
[@cmd_output, @cmd_status]
end
end
end
end