@@ -187,7 +187,14 @@ def diff(
187
187
kwargs ["as_process" ] = True
188
188
proc = diff_cmd (* self ._process_diff_args (args ), ** kwargs )
189
189
190
- diff_method = Diff ._index_from_patch_format if create_patch else Diff ._index_from_raw_format
190
+ cmdline = getattr (proc , 'args' , '' ) # PY3+ only
191
+
192
+ if '--name-only' in cmdline :
193
+ diff_method = Diff ._index_from_name_only_format
194
+ elif create_patch :
195
+ diff_method = Diff ._index_from_patch_format
196
+ else :
197
+ diff_method = Diff ._index_from_raw_format
191
198
index = diff_method (self .repo , proc )
192
199
193
200
proc .wait ()
@@ -569,6 +576,34 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
569
576
570
577
return index
571
578
579
+ @classmethod
580
+ def _index_from_name_only_format (cls , repo , proc ):
581
+ """Create a new DiffIndex from the given text which must be in name only format
582
+ :param repo: is the repository we are operating on - it is required
583
+ :param stream: result of 'git diff' as a stream (supporting file protocol)
584
+ :return: git.DiffIndex """
585
+
586
+ cls .is_first = True
587
+
588
+ index = DiffIndex ()
589
+
590
+ def handle_diff_line_name_only (line ):
591
+ path = line .decode (defenc )
592
+ if cls .is_first :
593
+ cls .is_first = False
594
+ return
595
+
596
+ path = path .strip ()
597
+ a_path = path .encode (defenc )
598
+ b_path = path .encode (defenc )
599
+ index .append (Diff (repo , a_path , b_path , None , None , None , None ,
600
+ False , False , None , None , None ,
601
+ '' , None , None ))
602
+
603
+ handle_process_output (proc , handle_diff_line_name_only , None , finalize_process , decode_streams = False )
604
+
605
+ return index
606
+
572
607
@staticmethod
573
608
def _handle_diff_line (lines_bytes : bytes , repo : "Repo" , index : DiffIndex ) -> None :
574
609
lines = lines_bytes .decode (defenc )
0 commit comments