@@ -148,7 +148,8 @@ def diff(
148148 if not any (x in kwargs for x in ('find_renames' , 'no_renames' , 'M' )):
149149 args .append ("-M" )
150150
151- if create_patch :
151+ name_only = 'name-only' in kwargs
152+ if not name_only and create_patch :
152153 args .append ("-p" )
153154 else :
154155 args .append ("--raw" )
@@ -170,6 +171,7 @@ def diff(
170171 elif other is NULL_TREE :
171172 args .insert (0 , "-r" ) # recursive diff-tree
172173 args .insert (0 , "--root" )
174+ Diff .is_first = True
173175 diff_cmd = self .repo .git .diff_tree
174176 elif other is not None :
175177 args .insert (0 , "-r" ) # recursive diff-tree
@@ -576,29 +578,33 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
576578
577579 return index
578580
581+ is_first = False
582+
579583 @classmethod
580584 def _index_from_name_only_format (cls , repo , proc ):
581585 """Create a new DiffIndex from the given text which must be in name only format
582586 :param repo: is the repository we are operating on - it is required
583587 :param stream: result of 'git diff' as a stream (supporting file protocol)
584588 :return: git.DiffIndex """
585589
586- cls .is_first = True
587-
588590 index = DiffIndex ()
589591
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 ))
602608
603609 handle_process_output (proc , handle_diff_line_name_only , None , finalize_process , decode_streams = False )
604610
0 commit comments