|
33 | 33 | import pygit2 |
34 | 34 | from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED |
35 | 35 | from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL |
| 36 | +from pygit2 import GIT_DIFF_SHOW_BINARY |
36 | 37 | from pygit2 import GIT_DELTA_RENAMED |
37 | 38 | from . import utils |
38 | 39 | from itertools import chain |
|
63 | 64 | -c/d contents |
64 | 65 | """ |
65 | 66 |
|
| 67 | +PATCH_BINARY = """diff --git a/binary_file b/binary_file |
| 68 | +index 86e5c10..b835d73 100644 |
| 69 | +Binary files a/binary_file and b/binary_file differ |
| 70 | +""" |
| 71 | + |
| 72 | +PATCH_BINARY_SHOW = """diff --git a/binary_file b/binary_file |
| 73 | +index 86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6..b835d73543244b6694f36a8c5dfdffb71b153db7 100644 |
| 74 | +GIT binary patch |
| 75 | +literal 8 |
| 76 | +Pc${NM%FIhFs^kIy3n&7R |
| 77 | +
|
| 78 | +literal 8 |
| 79 | +Pc${NM&PdElPvrst3ey5{ |
| 80 | +""" |
| 81 | + |
66 | 82 | DIFF_HEAD_TO_INDEX_EXPECTED = [ |
67 | 83 | 'staged_changes', |
68 | 84 | 'staged_changes_file_deleted', |
@@ -308,5 +324,15 @@ def test_diff_stats(self): |
308 | 324 | width=80) |
309 | 325 | self.assertEqual(STATS_EXPECTED, formatted) |
310 | 326 |
|
| 327 | + |
| 328 | +class BinaryDiffTest(utils.BinaryFileRepoTestCase): |
| 329 | + def test_binary_diff(self): |
| 330 | + repo = self.repo |
| 331 | + diff = repo.diff('HEAD', 'HEAD^') |
| 332 | + self.assertEqual(PATCH_BINARY, diff.patch) |
| 333 | + diff = repo.diff('HEAD', 'HEAD^', flags=GIT_DIFF_SHOW_BINARY) |
| 334 | + self.assertEqual(PATCH_BINARY_SHOW, diff.patch) |
| 335 | + |
| 336 | + |
311 | 337 | if __name__ == '__main__': |
312 | 338 | unittest.main() |
0 commit comments