def merge(local_text, original_text, remote_text)
original_file = tempfile("wfo.original", original_text)
local_file = tempfile("wfo.local", local_text)
remote_file = tempfile("wfo.remote", remote_text)
command = ['diff3', '-mE',
'-L', 'edited by you',
'-L', 'before edited',
'-L', 'edited by others',
local_file.path,
original_file.path,
remote_file.path]
merged = IO.popen(Escape.shell_command(command), 'r') {|f|
f.read
}
status = $?
unless status.exited?
raise "[bug] unexpected diff3 failure: #{status.inspect}"
end
case status.exitstatus
when 0
conflict = false
when 1
conflict = true
when 2
raise "diff3 failed"
else
raise "[bug] unexpected diff3 status: #{status.inspect}"
end
return merged, conflict
end