pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

Wrong binary state of a delta if patches have not been iterated

Open matze opened this issue 6 years ago • 0 comments

Much to my surprise reading delta.is_binary returns the wrong value if one does not iterate over the patches beforehand. Given

mkdir test && cd test
touch README.md
dd if=/dev/urandom of=data.bin bs=256K count=1
git init .
git add README.md && git commit -m "initial"
git add data.bin && git commit -m "binary"

this script

import pygit2

repo = pygit2.Repository('.git')
diff = repo.diff('HEAD', 'HEAD~1')

for delta in diff.deltas:
    print(delta.is_binary)

for patch in diff:
    pass

for delta in diff.deltas:
    print(delta.is_binary)

prints

False
True

matze avatar Dec 05 '19 14:12 matze