rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Diff.find_similar! misreports binary files as different

Open lowjoel opened this issue 8 years ago • 1 comments

Given the repository attached, and this small script:

require 'rugged'
repo = Rugged::Repository.new('repro/.git')
diff = Rugged::Tree.diff(repo,
                         repo.rev_parse('309dd700bcfa6de727c43f159013f5b109412669').tree,
                         repo.rev_parse('f010d6f0c3ede1d69ef387d63afc7cc334632c8e').tree,
                         show_binary: true)
diff.find_similar!

puts diff.map(&:to_s).join("\n")

The resulting diff shows this:

diff --git a/white.png b/rename.png
similarity index 100%
rename from white.png
rename to rename.png
Binary files a/white.png and b/rename.png differ

I did not expect the last line to appear, since the file was renamed in-place:

$ git show -p --binary f010d6f
commit f010d6f0c3ede1d69ef387d63afc7cc334632c8e (HEAD -> master)
Author: Joel Low <[email protected]>
Date:   Thu Sep 28 14:20:15 2017 +0800

    Rename binary file

diff --git a/white.png b/rename.png
similarity index 100%
rename from white.png
rename to rename.png

lowjoel avatar Sep 28 '17 06:09 lowjoel

Reproduce repository: repro.zip

lowjoel avatar Sep 28 '17 06:09 lowjoel