Skip to content

Commit

Permalink
diff: by limiting the splitcount to 5, a subtle bug was introduced as…
Browse files Browse the repository at this point in the history
… 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 :)
  • Loading branch information
Byron committed May 25, 2010
1 parent 600fcbc commit 1019d4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def _index_from_raw_format(cls, repo, stream):
continue
# END its not a valid diff line
old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
path = path.strip()
a_path = path
b_path = path
deleted_file = False
Expand Down
16 changes: 15 additions & 1 deletion test/git/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,30 @@
from git import *

class TestDiff(TestBase):

def _assert_diff_format(self, diffs):
# verify that the format of the diff is sane
for diff in diffs:
if diff.a_blob:
assert not diff.a_blob.path.endswith('\n')
if diff.b_blob:
assert not diff.b_blob.path.endswith('\n')
# END for each diff
return diffs

def test_list_from_string_new_mode(self):
output = ListProcessAdapter(fixture('diff_new_mode'))
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
self._assert_diff_format(diffs)

assert_equal(1, len(diffs))
assert_equal(10, len(diffs[0].diff.splitlines()))

def test_diff_with_rename(self):
output = ListProcessAdapter(fixture('diff_rename'))
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)

self._assert_diff_format(diffs)

assert_equal(1, len(diffs))

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

if diff_index:
self._assert_diff_format(diff_index)
for ct in DiffIndex.change_type:
key = 'ct_%s'%ct
assertion_map.setdefault(key, 0)
Expand Down

0 comments on commit 1019d4c

Please sign in to comment.