@@ -46,7 +46,7 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
4646 if ( ! isComparisonInputLine ( ctx . getCurLine ( ) ) ) {
4747 return ;
4848 }
49- ctx . nextLine ( ) ;
49+ const comparisonLineParsed = parseComparisonInputLine ( ctx ) ;
5050
5151 let isDeleted = false ;
5252 let isNew = false ;
@@ -55,11 +55,18 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
5555 let pathAfter = '' ;
5656 while ( ! ctx . isEof ( ) ) {
5757 const extHeader = parseExtendedHeader ( ctx ) ;
58+
5859 if ( ! extHeader ) {
5960 break ;
6061 }
61- if ( extHeader . type === ExtendedHeader . Deleted ) isDeleted = true ;
62- if ( extHeader . type === ExtendedHeader . NewFile ) isNew = true ;
62+ if ( extHeader . type === ExtendedHeader . Deleted ) {
63+ isDeleted = true ;
64+ pathBefore = comparisonLineParsed ?. from || '' ;
65+ }
66+ if ( extHeader . type === ExtendedHeader . NewFile ) {
67+ isNew = true ;
68+ pathAfter = comparisonLineParsed ?. to || '' ;
69+ }
6370 if ( extHeader . type === ExtendedHeader . RenameFrom ) {
6471 isRename = true ;
6572 pathBefore = extHeader . path as string ;
@@ -73,33 +80,30 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
7380 const changeMarkers = parseChangeMarkers ( ctx ) ;
7481 const chunks = parseChunks ( ctx ) ;
7582
76- if ( isDeleted && changeMarkers ) {
83+ if ( isDeleted && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
7784 return {
7885 type : FileType . Deleted ,
7986 chunks,
80- path : changeMarkers . deleted ,
87+ path : chunks [ 0 ] . pathBefore ,
8188 } ;
82- } else if (
83- isDeleted &&
84- chunks . length &&
85- chunks [ 0 ] . type === 'BinaryFilesChunk'
86- ) {
89+ }
90+ if ( isDeleted ) {
8791 return {
8892 type : FileType . Deleted ,
8993 chunks,
90- path : chunks [ 0 ] . pathBefore ,
94+ path : changeMarkers ?. deleted || pathBefore ,
9195 } ;
92- } else if ( isNew && changeMarkers ) {
96+ } else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
9397 return {
9498 type : FileType . Added ,
9599 chunks,
96- path : changeMarkers . added ,
100+ path : chunks [ 0 ] . pathAfter ,
97101 } ;
98- } else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
102+ } else if ( isNew ) {
99103 return {
100104 type : FileType . Added ,
101105 chunks,
102- path : chunks [ 0 ] . pathAfter ,
106+ path : changeMarkers ?. added || pathAfter ,
103107 } ;
104108 } else if ( isRename ) {
105109 return {
@@ -133,6 +137,20 @@ function isComparisonInputLine(line: string): boolean {
133137 return line . indexOf ( 'diff' ) === 0 ;
134138}
135139
140+ function parseComparisonInputLine (
141+ ctx : Context
142+ ) : { from : string ; to : string } | null {
143+ const line = ctx . getCurLine ( ) ;
144+ const splitted = line . split ( ' ' ) . reverse ( ) ;
145+ const to = splitted . find ( ( p ) => p . startsWith ( 'b/' ) ) ?. replace ( 'b/' , '' ) ;
146+ const from = splitted . find ( ( p ) => p . startsWith ( 'a/' ) ) ?. replace ( 'a/' , '' ) ;
147+ ctx . nextLine ( ) ;
148+ if ( to && from ) {
149+ return { to, from } ;
150+ }
151+ return null ;
152+ }
153+
136154function parseChunks ( context : Context ) : AnyChunk [ ] {
137155 const chunks : AnyChunk [ ] = [ ] ;
138156
0 commit comments