@@ -148,7 +148,8 @@ def diff(
148
148
if not any (x in kwargs for x in ('find_renames' , 'no_renames' , 'M' )):
149
149
args .append ("-M" )
150
150
151
- if create_patch :
151
+ name_only = 'name-only' in kwargs
152
+ if not name_only and create_patch :
152
153
args .append ("-p" )
153
154
else :
154
155
args .append ("--raw" )
@@ -170,6 +171,7 @@ def diff(
170
171
elif other is NULL_TREE :
171
172
args .insert (0 , "-r" ) # recursive diff-tree
172
173
args .insert (0 , "--root" )
174
+ Diff .is_first = True
173
175
diff_cmd = self .repo .git .diff_tree
174
176
elif other is not None :
175
177
args .insert (0 , "-r" ) # recursive diff-tree
@@ -576,29 +578,33 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
576
578
577
579
return index
578
580
581
+ is_first = False
582
+
579
583
@classmethod
580
584
def _index_from_name_only_format (cls , repo , proc ):
581
585
"""Create a new DiffIndex from the given text which must be in name only format
582
586
:param repo: is the repository we are operating on - it is required
583
587
:param stream: result of 'git diff' as a stream (supporting file protocol)
584
588
:return: git.DiffIndex """
585
589
586
- cls .is_first = True
587
-
588
590
index = DiffIndex ()
589
591
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 ))
592
+ def handle_diff_line_name_only (lines ):
593
+ lines = lines .decode (defenc )
594
+
595
+ for line in lines .split ('\x00 ' ):
596
+ path = line .strip ()
597
+ if len (path ) == 0 :
598
+ continue
599
+ if cls .is_first :
600
+ cls .is_first = False
601
+ continue
602
+
603
+ a_path = path .encode (defenc )
604
+ b_path = path .encode (defenc )
605
+ index .append (Diff (repo , a_path , b_path , None , None , None , None ,
606
+ False , False , None , None , None ,
607
+ '' , None , None ))
602
608
603
609
handle_process_output (proc , handle_diff_line_name_only , None , finalize_process , decode_streams = False )
604
610
0 commit comments