@@ -49,6 +49,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
49
49
If None, we will be compared to the working tree.
50
50
If Treeish, it will be compared against the respective tree
51
51
If Index ( type ), it will be compared against the index.
52
+ If the string 'root', it will compare the empty tree against this tree.
52
53
It defaults to Index to assure the method will not by-default fail
53
54
on bare repositories.
54
55
@@ -87,10 +88,15 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
87
88
if paths is not None and not isinstance (paths , (tuple , list )):
88
89
paths = [paths ]
89
90
90
- if other is not None and other is not self .Index :
91
- args .insert (0 , other )
91
+ diff_cmd = self .repo .git .diff
92
92
if other is self .Index :
93
- args .insert (0 , "--cached" )
93
+ args .insert (0 , '--cached' )
94
+ elif other == 'root' :
95
+ args .insert (0 , '--root' )
96
+ diff_cmd = self .repo .git .diff_tree
97
+ elif other is not None :
98
+ args .insert (0 , other )
99
+ diff_cmd = self .repo .git .diff_tree
94
100
95
101
args .insert (0 , self )
96
102
@@ -101,7 +107,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
101
107
# END paths handling
102
108
103
109
kwargs ['as_process' ] = True
104
- proc = self . repo . git . diff (* self ._process_diff_args (args ), ** kwargs )
110
+ proc = diff_cmd (* self ._process_diff_args (args ), ** kwargs )
105
111
106
112
diff_method = Diff ._index_from_raw_format
107
113
if create_patch :
0 commit comments