From 82b533f86cf86c96a16f96c815533bdda0585f48 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Thu, 14 Apr 2016 12:43:54 +0200 Subject: Use a special object rather than a string This alternative API does not prevent users from using the valid treeish "root". --- git/diff.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index eada73b9..67d1986c 100644 --- a/git/diff.py +++ b/git/diff.py @@ -18,6 +18,9 @@ from git.compat import ( __all__ = ('Diffable', 'DiffIndex', 'Diff') +# Special object to compare against the empty tree in diffs +NULL_TREE = object() + class Diffable(object): @@ -49,7 +52,7 @@ class Diffable(object): 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. @@ -91,7 +94,7 @@ class Diffable(object): 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: -- cgit v1.2.1