Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Enable git diff-tree with empty second tree-ish param
Executing `git diff-tree` and omitting the second tree-ish argument
wasn't possible before. This commit enables this behaviour by allowing
the caller to send in an empty string.

Allowing an empty string keeps backwards compatibility for all other
allowed input types.
  • Loading branch information
gangefors committed Mar 27, 2018
commit 7a8ba96c29b66e0c1d11c6bc885ac6efbd06a115
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.
4 changes: 3 additions & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ 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 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')