Skip to content
Prev Previous commit
Next Next commit
Use a special object rather than a string
This alternative API does not prevent users from using the valid treeish
"root".
  • Loading branch information
nvie committed Apr 14, 2016
commit 82b533f86cf86c96a16f96c815533bdda0585f48
7 changes: 5 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

__all__ = ('Diffable', 'DiffIndex', 'Diff')

# Special object to compare against the empty tree in diffs
NULL_TREE = object()


class Diffable(object):

Expand Down Expand Up @@ -49,7 +52,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
If None, we will be compared to the working tree.
If Treeish, it will be compared against the respective tree
If Index ( type ), it will be compared against the index.
If the string 'root', it will compare the empty tree against this tree.
If git.NULL_TREE, it will compare against the empty tree.
It defaults to Index to assure the method will not by-default fail
on bare repositories.

Expand Down Expand Up @@ -91,7 +94,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
diff_cmd = self.repo.git.diff
if other is self.Index:
args.insert(0, '--cached')
elif other == 'root':
elif other is NULL_TREE:
args.insert(0, '--root')
diff_cmd = self.repo.git.diff_tree
elif other is not None:
Expand Down