diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-05-25 20:11:43 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-05-25 20:11:43 +0200 |
commit | 1019d4cf68d1acdbb4d6c1abb7e71ac9c0f581af (patch) | |
tree | db7d88fc1be70144135c160971d853aa2b8ff6bb | |
parent | 600fcbc1a2d723f8d51e5f5ab6d9e4c389010e1c (diff) | |
download | gitpython-0.2.0-beta1.tar.gz |
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 fix0.2.0-beta1
Wow, at least two people reviewd the code, but it slipped through anyway :)
-rw-r--r-- | lib/git/diff.py | 1 | ||||
-rw-r--r-- | test/git/test_diff.py | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py index 0dd4ed6e..9df0c499 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -343,6 +343,7 @@ class Diff(object): 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 diff --git a/test/git/test_diff.py b/test/git/test_diff.py index 5df39df1..2f6a19bd 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -8,17 +8,30 @@ from test.testlib import * 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] @@ -54,6 +67,7 @@ class TestDiff(TestBase): 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) |