@@ -146,9 +146,15 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
146
146
kwargs ['as_process' ] = True
147
147
proc = diff_cmd (* self ._process_diff_args (args ), ** kwargs )
148
148
149
- diff_method = (Diff ._index_from_patch_format
150
- if create_patch
151
- else Diff ._index_from_raw_format )
149
+ cmdline = getattr (proc , 'args' , '' ) # PY3+ only
150
+
151
+ if '--name-only' in cmdline :
152
+ diff_method = Diff ._index_from_name_only_format
153
+ elif create_patch :
154
+ diff_method = Diff ._index_from_patch_format
155
+ else :
156
+ diff_method = Diff ._index_from_raw_format
157
+
152
158
index = diff_method (self .repo , proc )
153
159
154
160
proc .wait ()
@@ -478,6 +484,34 @@ def _index_from_patch_format(cls, repo, proc):
478
484
479
485
return index
480
486
487
+ @classmethod
488
+ def _index_from_name_only_format (cls , repo , proc ):
489
+ """Create a new DiffIndex from the given text which must be in name only format
490
+ :param repo: is the repository we are operating on - it is required
491
+ :param stream: result of 'git diff' as a stream (supporting file protocol)
492
+ :return: git.DiffIndex """
493
+
494
+ cls .is_first = True
495
+
496
+ index = DiffIndex ()
497
+
498
+ def handle_diff_line_name_only (line ):
499
+ path = line .decode (defenc )
500
+ if cls .is_first :
501
+ cls .is_first = False
502
+ return
503
+
504
+ path = path .strip ()
505
+ a_path = path .encode (defenc )
506
+ b_path = path .encode (defenc )
507
+ index .append (Diff (repo , a_path , b_path , None , None , None , None ,
508
+ False , False , None , None , '' ,
509
+ None , None , None ))
510
+
511
+ handle_process_output (proc , handle_diff_line_name_only , None , finalize_process , decode_streams = False )
512
+
513
+ return index
514
+
481
515
@classmethod
482
516
def _index_from_raw_format (cls , repo , proc ):
483
517
"""Create a new DiffIndex from the given stream which must be in raw format.
0 commit comments