summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-09 16:54:33 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-09 17:16:35 +0100
commit85a5a8c6a931f8b3a220ed61750d1f9758d0810a (patch)
treef17894d78fa475e53cbc2f1bdfa1b8aa21e2893f
parent18caa610d50b92331485013584f5373804dd0416 (diff)
downloadgitpython-85a5a8c6a931f8b3a220ed61750d1f9758d0810a.tar.gz
Fixed mode-handling in Diff creation, and added assertions to catch this in future
There is still some work todo in terms of how we handle the encoding
-rw-r--r--git/diff.py7
-rw-r--r--git/test/test_diff.py6
2 files changed, 10 insertions, 3 deletions
diff --git a/git/diff.py b/git/diff.py
index f10bd1cd..595a8247 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -217,10 +217,12 @@ class Diff(object):
if a_blob_id is None:
self.a_blob = None
else:
+ assert self.a_mode
self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=a_path)
if b_blob_id is None:
self.b_blob = None
else:
+ assert self.b_mode
self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=b_path)
self.new_file = new_file
@@ -313,8 +315,9 @@ class Diff(object):
# Make sure the mode is set if the path is set. Otherwise the resulting blob is invalid
# We just use the one mode we should have parsed
- index.append(Diff(repo, a_path, b_path, a_blob_id, b_blob_id,
- old_mode or deleted_file_mode or b_mode, new_mode or new_file_mode or b_mode,
+ a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode))
+ b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode)
+ index.append(Diff(repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, b_mode,
new_file, deleted_file, rename_from, rename_to, None))
previous_header = header
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index c59117ef..498f0586 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -73,7 +73,7 @@ class TestDiff(TestBase):
assert len(list(res.iter_change_type('M'))) == 1
if res[0].diff:
assert res[0].diff == "Binary files a/rps and b/rps differ\n", "in patch mode, we get a diff text"
- assert isinstance(str(res[0]), str), "This call should just work"
+ assert str(res[0]), "This call should just work"
# end for each method to test
def test_diff_index(self):
@@ -82,6 +82,7 @@ class TestDiff(TestBase):
assert len(res) == 6
for dr in res:
assert dr.diff
+ assert str(dr), "Diff to string conversion should be possible"
# end for each diff
dr = res[3]
@@ -129,6 +130,9 @@ class TestDiff(TestBase):
assert len(diff_set) == 1
assert diff_index[0] == diff_index[0]
assert not (diff_index[0] != diff_index[0])
+
+ for dr in diff_index:
+ assert str(dr), "Diff to string conversion should be possible"
# END diff index checking
# END for each patch option
# END for each path option