rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.64k stars 380 forks source link

Mismatched binary detection behaviour on diffs #991

Open FintanH opened 9 months ago

FintanH commented 9 months ago

Hey :wave:

I have a peculiar case that I've created a reproducible for. If you clone this repository https://github.com/FintanH/git2-binary-check and do cargo run, you'll get the following output:

Path: "bin/cat"
Is binary: false
Path: "bin/ls"
Is binary: false
Path: "bin/test"
Is binary: false

However, if you were to run git diff 373b3404371e359404392aff715d504293112c8b abdedcec89e3c48ac520e4a96c7ea39364316b9e, you'll get:

diff --git a/bin/cat b/bin/cat
new file mode 100755
index 0000000..0bbb14b
Binary files /dev/null and b/bin/cat differ
diff --git a/bin/ls b/bin/ls
new file mode 100755
index 0000000..87c2d51
Binary files /dev/null and b/bin/ls differ
diff --git a/bin/test b/bin/test
new file mode 100755
index 0000000..0cced79
Binary files /dev/null and b/bin/test differ

It seems like git2, and possibly libgit2, are not detecting binary files in the same manner as the git CLI is doing.

I checked on git2-0.17.0 and git2-018.1 and my git version is git version 2.40.1.

Let me know if I can do anything else to help track down this discrepancy.

extrawurst commented 9 months ago

and possibly libgit2

then its probably better to post the repro there

FintanH commented 9 months ago

and possibly libgit2

then its probably better to post the repro there

Thanks for the response, you're right. My C is rusty (pun intended), so it was quicker for me to write a reproducible in Rust first -- and since this library directly relies on the behaviour of libgit2 I thought it would be in this project's interest to know about the potential bug too :)

extrawurst commented 9 months ago

people post the git2-rs based rust repros there too, don't be shy :)

ehuss commented 9 months ago

The main.rs in the repo only prints "Hello, world!". Is it perhaps missing the reproduction code?

FintanH commented 9 months ago

Ah sorry! I did forget to push the changes, but they're there now, thanks :bow: