@@ -49,6 +49,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
4949 If None, we will be compared to the working tree.
5050 If Treeish, it will be compared against the respective tree
5151 If Index ( type ), it will be compared against the index.
52+ If the string 'root', it will compare the empty tree against this tree.
5253 It defaults to Index to assure the method will not by-default fail
5354 on bare repositories.
5455
@@ -87,10 +88,15 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
8788 if paths is not None and not isinstance (paths , (tuple , list )):
8889 paths = [paths ]
8990
90- if other is not None and other is not self .Index :
91- args .insert (0 , other )
91+ diff_cmd = self .repo .git .diff
9292 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
94100
95101 args .insert (0 , self )
96102
@@ -101,7 +107,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
101107 # END paths handling
102108
103109 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 )
105111
106112 diff_method = Diff ._index_from_raw_format
107113 if create_patch :
0 commit comments