Method: Braid::Operations::Git#apply

Defined in:
lib/braid/operations.rb

#apply(diff, *args) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/braid/operations.rb', line 299

def apply(diff, *args)
  status, err = nil, nil

  command = "git apply --index --whitespace=nowarn #{args.join(' ')} -"

  if USE_OPEN3
    Open3.popen3(command) do |stdin, stdout, stderr, wait_thread|
      stdin.puts(diff)
      stdin.close
      err = stderr.read
      # Under earlier jrubies this is not correctly passed so add in check
      status = wait_thread.value if wait_thread # Process::Status object returned.
    end
    # Handle earlier jrubies such as 1.6.7.2
    status = $?.exitstatus if status.nil?
  else
    status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
      stdin.puts(diff)
      stdin.close
      err = stderr.read
    end.exitstatus
  end

  raise ShellExecutionError, err unless status == 0
  true
end