Skip to content

Commit 82b533f

Browse files
committed
Use a special object rather than a string
This alternative API does not prevent users from using the valid treeish "root".
1 parent aae2a73 commit 82b533f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

‎git/diff.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

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

21+
# Special object to compare against the empty tree in diffs
22+
NULL_TREE = object()
23+
2124

2225
class Diffable(object):
2326

@@ -49,7 +52,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
4952
If None, we will be compared to the working tree.
5053
If Treeish, it will be compared against the respective tree
5154
If Index ( type ), it will be compared against the index.
52-
If the string 'root', it will compare the empty tree against this tree.
55+
If git.NULL_TREE, it will compare against the empty tree.
5356
It defaults to Index to assure the method will not by-default fail
5457
on bare repositories.
5558
@@ -91,7 +94,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
9194
diff_cmd = self.repo.git.diff
9295
if other is self.Index:
9396
args.insert(0, '--cached')
94-
elif other == 'root':
97+
elif other is NULL_TREE:
9598
args.insert(0, '--root')
9699
diff_cmd = self.repo.git.diff_tree
97100
elif other is not None:

0 commit comments

Comments
 (0)