summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
authorVincent Driessen <me@nvie.com>2016-04-19 21:35:39 +0200
committerVincent Driessen <me@nvie.com>2016-04-19 21:35:39 +0200
commit4adafc5a99947301ca0ce40511991d6d54c57a41 (patch)
treee7cf8a66b178baf8fa4fcfddc46f2134c48042ab /git/diff.py
parent76e19e4221684f24ef881415ec6ccb6bab6eb8e8 (diff)
parent3297fe50067da728eb6f3f47764efb223e0d6ea4 (diff)
downloadgitpython-4adafc5a99947301ca0ce40511991d6d54c57a41.tar.gz
Merge pull request #408 from nvie/master
Add support for diffing against root commit
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/git/diff.py b/git/diff.py
index 062220df..de3aa1e8 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -16,7 +16,10 @@ from git.compat import (
)
-__all__ = ('Diffable', 'DiffIndex', 'Diff')
+__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
+
+# Special object to compare against the empty tree in diffs
+NULL_TREE = object()
class Diffable(object):
@@ -49,6 +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 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.
@@ -87,10 +91,17 @@ class Diffable(object):
if paths is not None and not isinstance(paths, (tuple, list)):
paths = [paths]
- if other is not None and other is not self.Index:
- args.insert(0, other)
+ diff_cmd = self.repo.git.diff
if other is self.Index:
- args.insert(0, "--cached")
+ args.insert(0, '--cached')
+ elif other is NULL_TREE:
+ args.insert(0, '-r') # recursive diff-tree
+ args.insert(0, '--root')
+ diff_cmd = self.repo.git.diff_tree
+ elif other is not None:
+ args.insert(0, '-r') # recursive diff-tree
+ args.insert(0, other)
+ diff_cmd = self.repo.git.diff_tree
args.insert(0, self)
@@ -101,7 +112,7 @@ class Diffable(object):
# END paths handling
kwargs['as_process'] = True
- proc = self.repo.git.diff(*self._process_diff_args(args), **kwargs)
+ proc = diff_cmd(*self._process_diff_args(args), **kwargs)
diff_method = Diff._index_from_raw_format
if create_patch: