diff options
-rw-r--r-- | lib/git/objects/base.py | 7 | ||||
-rw-r--r-- | test/git/test_diff.py | 30 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index 1bb2e8f1..b347b5f1 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -214,6 +214,9 @@ class Diffable(object): Note Rename detection will only work if create_patch is True """ + # import it in a retared fashion to avoid dependency cycle + from git.diff import Diff + args = list(self._diff_args[:]) args.append( "--abbrev=40" ) # we need full shas args.append( "--full-index" ) # get full index paths, not only filenames @@ -237,9 +240,9 @@ class Diffable(object): kwargs['as_process'] = True proc = self.repo.git.diff(*args, **kwargs) - diff_method = diff.Diff._index_from_raw_format + diff_method = Diff._index_from_raw_format if create_patch: - diff_method = diff.Diff._index_from_patch_format(self.repo, proc.stdout) + diff_method = Diff._index_from_patch_format return diff_method(self.repo, proc.stdout) diff --git a/test/git/test_diff.py b/test/git/test_diff.py index ea83145d..166ce310 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -28,5 +28,35 @@ class TestDiff(TestCase): assert_equal(diff.rename_from, 'AUTHORS') assert_equal(diff.rename_to, 'CONTRIBUTORS') + def test_diff_patch_format(self): + # test all of the 'old' format diffs for completness - it should at least + # be able to deal with it + fixtures = ("diff_2", "diff_2f", "diff_f", "diff_i", "diff_mode_only", + "diff_new_mode", "diff_numstat", "diff_p", "diff_rename", + "diff_tree_numstat_root" ) + + for fixture_name in fixtures: + diff_proc = ListProcessAdapter(fixture(fixture_name)) + diffs = Diff._index_from_patch_format(self.repo, diff_proc.stdout) + # END for each fixture + def test_diff_interface(self): + # test a few variations of the main diff routine + for i, commit in enumerate(self.repo.iter_commits('0.1.6', max_count=10)): + diff_item = commit + if i%2 == 0: + diff_item = commit.tree + # END use tree every second item + + for other in (None, commit.parents[0]): + for paths in (None, "CHANGES", ("CHANGES", "lib")): + for create_patch in range(2): + diff_index = diff_item.diff(other, paths, create_patch) + assert diff_index + # END for each patch option + # END for each path option + # END for each other side + # END for each commit + + self.fail( "TODO: Test full diff interface on commits, trees, index, patch and non-patch" ) |