diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-09-13 00:52:43 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2017-09-20 14:21:54 +0300 |
commit | 34eeac6108c0ae764c7acf09a42e1151fc90d7fb (patch) | |
tree | 3dcb6771904c0ea1ec68dc794bb6c248b81124ff /lib/gitlab/git/popen.rb | |
parent | 36dc65d5ca34234faf8e79106ed081a28659d899 (diff) |
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
Diffstat (limited to 'lib/gitlab/git/popen.rb')
-rw-r--r-- | lib/gitlab/git/popen.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/gitlab/git/popen.rb b/lib/gitlab/git/popen.rb index 25fa62ce4bd..3d2fc471d28 100644 --- a/lib/gitlab/git/popen.rb +++ b/lib/gitlab/git/popen.rb @@ -5,17 +5,21 @@ require 'open3' module Gitlab module Git module Popen - def popen(cmd, path) + def popen(cmd, path, vars = {}) unless cmd.is_a?(Array) raise "System commands must be given as an array of strings" end - vars = { "PWD" => path } + 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 |