@@ -46,7 +46,7 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
4646 if ( ! isComparisonInputLine ( ctx . getCurLine ( ) ) ) {
4747 return ;
4848 }
49- ctx . nextLine ( ) ;
49+ const comparisonLineParsed = pasreComparisonInputLine ( ctx ) ;
5050
5151 let isDeleted = false ;
5252 let isNew = false ;
@@ -55,11 +55,15 @@ 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 }
6162 if ( extHeader . type === ExtendedHeader . Deleted ) isDeleted = true ;
62- if ( extHeader . type === ExtendedHeader . NewFile ) isNew = true ;
63+ if ( extHeader . type === ExtendedHeader . NewFile ) {
64+ isNew = true ;
65+ pathAfter = comparisonLineParsed ?. to || '' ;
66+ }
6367 if ( extHeader . type === ExtendedHeader . RenameFrom ) {
6468 isRename = true ;
6569 pathBefore = extHeader . path as string ;
@@ -89,11 +93,11 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
8993 chunks,
9094 path : chunks [ 0 ] . pathBefore ,
9195 } ;
92- } else if ( isNew && changeMarkers ) {
96+ } else if ( isNew ) {
9397 return {
9498 type : FileType . Added ,
9599 chunks,
96- path : changeMarkers . added ,
100+ path : changeMarkers ? changeMarkers . added : pathAfter ,
97101 } ;
98102 } else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
99103 return {
@@ -133,6 +137,20 @@ function isComparisonInputLine(line: string): boolean {
133137 return line . indexOf ( 'diff' ) === 0 ;
134138}
135139
140+ function pasreComparisonInputLine (
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