Skip to content

Add support for diffing against root commit #408

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

Merged
merged 12 commits into from
Apr 19, 2016
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