@@ -385,32 +385,49 @@ export function createLogParserWithFilesAndStats<T extends Record<string, unknow
385
385
if ( fieldCount < keys . length ) {
386
386
entry [ keys [ fieldCount ++ ] ] = field . value as ParsedEntryWithFilesAndStats < T > [ keyof T ] ;
387
387
} 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
+
389
412
// Skip binary files which show as - for both additions and deletions
390
413
if ( additions === '-' && deletions === '-' ) continue ;
391
414
392
415
const file : ParsedEntryFileWithStats = {
393
416
status :
394
- additions === '0' && deletions === '0'
417
+ status ??
418
+ ( additions === '0' && deletions === '0'
395
419
? 'M'
396
420
: additions === '0'
397
421
? 'D'
398
422
: deletions === '0'
399
423
? 'A'
400
- : 'M' ,
424
+ : 'M' ) ,
401
425
path : path ,
426
+ originalPath : originalPath ,
402
427
additions : additions === '-' ? 0 : parseInt ( additions , 10 ) ,
403
428
deletions : deletions === '-' ? 0 : parseInt ( deletions , 10 ) ,
404
429
} ;
405
430
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
-
414
431
files . push ( file ) ;
415
432
}
416
433
}
0 commit comments