@@ -385,32 +385,49 @@ export function createLogParserWithFilesAndStats<T extends Record<string, unknow
385385 if ( fieldCount < keys . length ) {
386386 entry [ keys [ fieldCount ++ ] ] = field . value as ParsedEntryWithFilesAndStats < T > [ keyof T ] ;
387387 } else {
388- const [ additions , deletions , path ] = field . value . split ( '\t' ) ;
388+ let [ additions , deletions , path ] = field . value . split ( '\t' ) ;
389+ additions = additions . trim ( ) ;
390+ deletions = deletions . trim ( ) ;
391+ path = path . trim ( ) ;
392+
393+ let originalPath ;
394+ let status ;
395+ // If we don't get a path it is likely a renamed file (because `-z` screws up the format)
396+ if ( ! path ) {
397+ field = fields . next ( ) ;
398+ path = field . value . trim ( ) ;
399+ field = fields . next ( ) ;
400+ originalPath = field . value . trim ( ) ;
401+ status = 'R' ;
402+ } else {
403+ // Handle renamed files which show as path/to/file => new/path/to/file
404+ const renameIndex = path . indexOf ( ' => ' ) ;
405+ if ( renameIndex !== - 1 ) {
406+ originalPath = path . substring ( 0 , renameIndex ) ;
407+ path = path . substring ( renameIndex + 4 ) ;
408+ status = 'R' ;
409+ }
410+ }
411+
389412 // Skip binary files which show as - for both additions and deletions
390413 if ( additions === '-' && deletions === '-' ) continue ;
391414
392415 const file : ParsedEntryFileWithStats = {
393416 status :
394- additions === '0' && deletions === '0'
417+ status ??
418+ ( additions === '0' && deletions === '0'
395419 ? 'M'
396420 : additions === '0'
397421 ? 'D'
398422 : deletions === '0'
399423 ? 'A'
400- : 'M' ,
424+ : 'M' ) ,
401425 path : path ,
426+ originalPath : originalPath ,
402427 additions : additions === '-' ? 0 : parseInt ( additions , 10 ) ,
403428 deletions : deletions === '-' ? 0 : parseInt ( deletions , 10 ) ,
404429 } ;
405430
406- // Handle renamed files which show as path/to/file => new/path/to/file
407- if ( path . includes ( ' => ' ) ) {
408- const [ originalPath , newPath ] = path . split ( ' => ' ) ;
409- file . originalPath = originalPath ;
410- file . path = newPath ;
411- file . status = 'R' ;
412- }
413-
414431 files . push ( file ) ;
415432 }
416433 }
0 commit comments