samg / diffy

Easy Diffing in Ruby
http://rubygems.org/gems/diffy
MIT License
1.26k stars 103 forks source link

diffy is incompatible with alpine linux/busybox linux diff #86

Open erkolson opened 7 years ago

erkolson commented 7 years ago

Though the diff binary that ships with Alpine linux will produce output as expected for differing files, diffy fails to produce any output.

I've tested diffy with all output types => :text, :color, :html, etc. I've also tested with variables and files.

After compiling gnu diff from source and installing in /usr/bin, diffy works!

erkolson commented 7 years ago

It is something with text encoding in the Open3.popen3() function?

You can reproduce it with this code:

#!/usr/bin/env ruby

require 'open3'

Open3.popen3('diff', '-U 10000', '/file1', '/file2') do |i, o, e|
  puts "o = #{o.read}"
  puts "e = #{e.read}"
end

It outputs this:

o =
e = diff: invalid number ' 10000'

A workaround is to pass a different value for :diff when invoking diffy:

puts Diffy::Diff.new('/file1', '/file2', {:source => 'files', :diff => '-U10000'})

I've tested diff with -U10000 on OS X, Alpine/Busybox, and Ubuntu; all work.

lremes commented 7 years ago

Tried the solution on ruby-alpine 2.4.1. The solution works on command line, but in rails the generated HTML diff results in "unchanged" for all lines.

Text output seems to work as expected: -first line +first changed line second line - +added line HTML output <div class="diff"> <ul> <li class="unchanged"><span>second line</span></li> </ul> </div>

hszeto commented 6 years ago

@erkolson :diff => '-U10000' did the trick! thanks! how did you find that out???

hszeto commented 6 years ago

is there a work around for :context ? It stops working again when I use :context....

hszeto commented 6 years ago

I just found out that :context => 0 is the same thing as :diff => '-U0'

bolshakov commented 6 years ago

Ruby 2.4.1, diffy 3.2.0, BusyBox v1.24.2 (2017-11-23 08:52:33 GMT) multi-call binary.

irb(main):029:0> Diffy::Diff.new("foo\n", "bar\n", diff: '-U0').to_s
=> "-foo\n+bar\n"
irb(main):030:0> Diffy::Diff.new("foo\n", "bar\n", diff: '-U0').to_s(:html)
=> "<div class=\"diff\"></div>"
v1ct0r commented 6 years ago

for me works only if redefine ORIGINAL_DEFAULT_OPTIONS constant (used in html_formatter.rb)

Diffy::Diff::ORIGINAL_DEFAULT_OPTIONS = {
      :diff => '-U10000',  # was :diff => '-U 10000',
      :source => 'strings',
      :include_diff_info => false,
      :include_plus_and_minus_in_html => false,
      :context => nil,
      :allow_empty_diff => true,
    }
Diffy::Diff.new("Hello!\n", "Hallo!\n", diff: '-U10000', include_plus_and_minus_in_html: true, include_diff_info: true).to_s(:html)

Result

=> "<div class=\"diff\">\n  <ul>\n    <li class=\"diff-comment\"><span>--- /tmp/diffy20180321-96-sulp0x</span></li>\n    <li class=\"diff-comment\"><span>+++ /tmp/diffy20180321-96-1tutkxl</span></li>\n    <li class=\"diff-block-info\"><span>@@ -1 +1 @@</span></li>\n    <li class=\"del\"><del><span class=\"symbol\">-</span>H<strong>e</strong>llo!</del></li>\n    <li class=\"ins\"><ins><span class=\"symbol\">+</span>H<strong>a</strong>llo!</ins></li>\n  </ul>\n</div>\n"