5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/nandoc/support/diff-proxy.rb', line 5
def diff path_a, path_b, opts={}
fail('no') unless File.exist?(path_a) && File.exist?(path_b)
rel_to = opts.delete(:relative_to)
path_a, path_b = relativize(rel_to, path_a, path_b) if rel_to
opts = {'--unified=3'=>nil, '--recursive'=>nil}.merge(opts)
args = ['diff'] + opts.each.map.flatten.compact + [path_a, path_b]
out = err = nil
block = proc do
out, err = sopen2(*args)
end
if rel_to
FileUtils.cd(rel_to, :verbose=>true, &block)
else
block.call
end
diff = Diff.new(out, err, args)
if diff.error?
return fail(diff.full_error_message){|f| f.diff = diff }
end
diff
end
|