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

Add support for GIT_DIFF_SHOW_BINARY #566

Merged
merged 1 commit into from Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pygit2.c
Expand Up @@ -323,6 +323,7 @@ moduleinit(PyObject* m)
ADD_CONSTANT_INT(m, GIT_DIFF_IGNORE_CASE)
ADD_CONSTANT_INT(m, GIT_DIFF_SHOW_UNTRACKED_CONTENT)
ADD_CONSTANT_INT(m, GIT_DIFF_SKIP_BINARY_CHECK)
ADD_CONSTANT_INT(m, GIT_DIFF_SHOW_BINARY)
ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE)
ADD_CONSTANT_INT(m, GIT_DIFF_INCLUDE_TYPECHANGE_TREES)
ADD_CONSTANT_INT(m, GIT_DIFF_RECURSE_IGNORED_DIRS)
Expand Down
Binary file added test/data/binaryfilerepo.tar
Binary file not shown.
26 changes: 26 additions & 0 deletions test/test_diff.py
Expand Up @@ -33,6 +33,7 @@
import pygit2
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL
from pygit2 import GIT_DIFF_SHOW_BINARY
from pygit2 import GIT_DELTA_RENAMED
from . import utils
from itertools import chain
Expand Down Expand Up @@ -63,6 +64,21 @@
-c/d contents
"""

PATCH_BINARY = """diff --git a/binary_file b/binary_file
index 86e5c10..b835d73 100644
Binary files a/binary_file and b/binary_file differ
"""

PATCH_BINARY_SHOW = """diff --git a/binary_file b/binary_file
index 86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6..b835d73543244b6694f36a8c5dfdffb71b153db7 100644
GIT binary patch
literal 8
Pc${NM%FIhFs^kIy3n&7R

literal 8
Pc${NM&PdElPvrst3ey5{
"""

DIFF_HEAD_TO_INDEX_EXPECTED = [
'staged_changes',
'staged_changes_file_deleted',
Expand Down Expand Up @@ -308,5 +324,15 @@ def test_diff_stats(self):
width=80)
self.assertEqual(STATS_EXPECTED, formatted)


class BinaryDiffTest(utils.BinaryFileRepoTestCase):
def test_binary_diff(self):
repo = self.repo
diff = repo.diff('HEAD', 'HEAD^')
self.assertEqual(PATCH_BINARY, diff.patch)
diff = repo.diff('HEAD', 'HEAD^', flags=GIT_DIFF_SHOW_BINARY)
self.assertEqual(PATCH_BINARY_SHOW, diff.patch)


if __name__ == '__main__':
unittest.main()
6 changes: 6 additions & 0 deletions test/utils.py
Expand Up @@ -160,6 +160,12 @@ class EmptyRepoTestCase(AutoRepoTestCase):

repo_spec = 'tar', 'emptyrepo'


class SubmoduleRepoTestCase(AutoRepoTestCase):

repo_spec = 'tar', 'submodulerepo'


class BinaryFileRepoTestCase(AutoRepoTestCase):

repo_spec = 'tar', 'binaryfilerepo'