diff --git a/AUTHORS b/AUTHORS index b5f0ebdc1..6b78aeefd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -26,5 +26,6 @@ Contributors are: -Mikuláš Poul -Charles Bouchard-Légaré -Yaroslav Halchenko +-Stefan Gangefors Portions derived from other open source works and are clearly marked. diff --git a/git/diff.py b/git/diff.py index d7221ac7d..a69c0926d 100644 --- a/git/diff.py +++ b/git/diff.py @@ -81,7 +81,8 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): :param other: Is the item to compare us with. - If None, we will be compared to the working tree. + If None, it will be compared to the working tree. + If empty string, it will be compared to it's parent with diff-tree. If Treeish, it will be compared against the respective tree If Index ( type ), it will be compared against the index. If git.NULL_TREE, it will compare against the empty tree. @@ -132,7 +133,8 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): diff_cmd = self.repo.git.diff_tree elif other is not None: args.insert(0, '-r') # recursive diff-tree - args.insert(0, other) + if other != '': + args.insert(0, other) diff_cmd = self.repo.git.diff_tree args.insert(0, self) diff --git a/git/test/test_diff.py b/git/test/test_diff.py index d21dde624..8d3ee63e3 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -266,3 +266,17 @@ def test_diff_interface(self): cp = c.parents[0] diff_index = c.diff(cp, ["does/not/exist"]) self.assertEqual(len(diff_index), 0) + + def test_diff_tree_empty_other(self): + initial_commit = self.rorepo.commit('9066712dca21ef35c534e068f2cc4fefdccf1ea3') + + # Test that we can use an empty string as other in a diff. + # It should do a diff-tree without the second tree-ish param + diff_index = initial_commit.diff('') + self.assertEqual(len(diff_index), 16) + self.assertEqual(diff_index[0].change_type, 'M') + self.assertTrue(diff_index[12].deleted_file) + self.assertTrue(diff_index[14].renamed) + self.assertEqual(diff_index[14].rename_from, 'test/asserts.py') + self.assertEqual(diff_index[14].rename_to, 'test/testlib/asserts.py') + self.assertEqual(diff_index[15].change_type, 'A')