Skip to content

Enable git diff-tree with empty second tree-ish param #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Contributors are:
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
-Yaroslav Halchenko <debian _at_ onerussian.com>
-Stefan Gangefors

Portions derived from other open source works and are clearly marked.
6 changes: 4 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions git/test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')