require 'open3'

module Gitlab
  module Git
    module Popen
      def popen(cmd, path)
        vars = { "PWD" => path }
        options = { :chdir => path }

        @cmd_output = ""
        @cmd_status = 0
        Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
          @cmd_status = wait_thr.value.exitstatus
          @cmd_output << stdout.read
          @cmd_output << stderr.read
        end

        return @cmd_output, @cmd_status
      end
    end
  end
end

require 'open3'

module Gitlab
  module Git
    module Popen
      def popen(cmd, path)
        vars = { "PWD" => path }
        options = { :chdir => path }

        @cmd_output = ""
        @cmd_status = 0
        Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
          @cmd_output << stdout.read
          @cmd_output << stderr.read
          @cmd_status = wait_thr.value.exitstatus
        end

        return @cmd_output, @cmd_status
      end
    end
  end
end

Read output before waiting for process to end
Read output before waiting for process to end

Sometimes a subprocess will not exit until it was able to write its
output to stdout/stderr. By waiting _after_ we read the subprocess
output, we avoid this potential bug.
