Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erkolson opened this issue Jun 1, 2017 · 7 comments
Open

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

erkolson opened this issue Jun 1, 2017 · 7 comments

Comments

@erkolson
Copy link

erkolson commented Jun 1, 2017

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
Copy link
Author

erkolson commented Jun 4, 2017

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
Copy link

lremes commented Jun 26, 2017

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
Copy link

hszeto commented Nov 7, 2017

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

@hszeto
Copy link

hszeto commented Nov 7, 2017

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

@hszeto
Copy link

hszeto commented Nov 7, 2017

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

@bolshakov
Copy link

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
Copy link

v1ct0r commented Mar 21, 2018

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants