Skip to content

Commit 1019d4c

Browse files
committed
diff: by limiting the splitcount to 5, a subtle bug was introduced as the newline at the end of the split line was not split away automatically. Added test for this, and the trivial fix
Wow, at least two people reviewd the code, but it slipped through anyway :)
1 parent 600fcbc commit 1019d4c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: lib/git/diff.py

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def _index_from_raw_format(cls, repo, stream):
343343
continue
344344
# END its not a valid diff line
345345
old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
346+
path = path.strip()
346347
a_path = path
347348
b_path = path
348349
deleted_file = False

Diff for: test/git/test_diff.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@
88
from git import *
99

1010
class TestDiff(TestBase):
11+
12+
def _assert_diff_format(self, diffs):
13+
# verify that the format of the diff is sane
14+
for diff in diffs:
15+
if diff.a_blob:
16+
assert not diff.a_blob.path.endswith('\n')
17+
if diff.b_blob:
18+
assert not diff.b_blob.path.endswith('\n')
19+
# END for each diff
20+
return diffs
1121

1222
def test_list_from_string_new_mode(self):
1323
output = ListProcessAdapter(fixture('diff_new_mode'))
1424
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
25+
self._assert_diff_format(diffs)
26+
1527
assert_equal(1, len(diffs))
1628
assert_equal(10, len(diffs[0].diff.splitlines()))
1729

1830
def test_diff_with_rename(self):
1931
output = ListProcessAdapter(fixture('diff_rename'))
2032
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
21-
33+
self._assert_diff_format(diffs)
34+
2235
assert_equal(1, len(diffs))
2336

2437
diff = diffs[0]
@@ -54,6 +67,7 @@ def test_diff_interface(self):
5467
assert isinstance(diff_index, DiffIndex)
5568

5669
if diff_index:
70+
self._assert_diff_format(diff_index)
5771
for ct in DiffIndex.change_type:
5872
key = 'ct_%s'%ct
5973
assertion_map.setdefault(key, 0)

0 commit comments

Comments
 (0)