Add support for GIT_DIFF_SHOW_BINARY
Adding the binary diff flag GIT_DIFF_SHOW_BINARY to pygit2. libgit2 0.23.0 already supports this constant to be used in diff flags and produces properly formated binary diffs.
This commit is contained in:
parent
ade211de60
commit
802976535a
@ -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)
|
||||
|
BIN
test/data/binaryfilerepo.tar
Normal file
BIN
test/data/binaryfilerepo.tar
Normal file
Binary file not shown.
@ -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()
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user