diff --git a/src/pygit2.c b/src/pygit2.c index 12d365f..cf613ae 100644 --- a/src/pygit2.c +++ b/src/pygit2.c @@ -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) diff --git a/test/data/binaryfilerepo.tar b/test/data/binaryfilerepo.tar new file mode 100644 index 0000000..c00fc93 Binary files /dev/null and b/test/data/binaryfilerepo.tar differ diff --git a/test/test_diff.py b/test/test_diff.py index b17d67c..f379216 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -33,6 +33,7 @@ import unittest 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 @@ -63,6 +64,21 @@ index 297efb8..0000000 -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', @@ -308,5 +324,15 @@ class DiffTest(utils.BareRepoTestCase): 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() diff --git a/test/utils.py b/test/utils.py index 0aa95d6..c8fa8e6 100644 --- a/test/utils.py +++ b/test/utils.py @@ -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'