@@ -46,7 +46,7 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
46
46
if ( ! isComparisonInputLine ( ctx . getCurLine ( ) ) ) {
47
47
return ;
48
48
}
49
- ctx . nextLine ( ) ;
49
+ const comparisonLineParsed = pasreComparisonInputLine ( ctx ) ;
50
50
51
51
let isDeleted = false ;
52
52
let isNew = false ;
@@ -55,11 +55,15 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
55
55
let pathAfter = '' ;
56
56
while ( ! ctx . isEof ( ) ) {
57
57
const extHeader = parseExtendedHeader ( ctx ) ;
58
+
58
59
if ( ! extHeader ) {
59
60
break ;
60
61
}
61
62
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
+ }
63
67
if ( extHeader . type === ExtendedHeader . RenameFrom ) {
64
68
isRename = true ;
65
69
pathBefore = extHeader . path as string ;
@@ -89,11 +93,11 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
89
93
chunks,
90
94
path : chunks [ 0 ] . pathBefore ,
91
95
} ;
92
- } else if ( isNew && changeMarkers ) {
96
+ } else if ( isNew ) {
93
97
return {
94
98
type : FileType . Added ,
95
99
chunks,
96
- path : changeMarkers . added ,
100
+ path : changeMarkers ? changeMarkers . added : pathAfter ,
97
101
} ;
98
102
} else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
99
103
return {
@@ -133,6 +137,20 @@ function isComparisonInputLine(line: string): boolean {
133
137
return line . indexOf ( 'diff' ) === 0 ;
134
138
}
135
139
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
+
136
154
function parseChunks ( context : Context ) : AnyChunk [ ] {
137
155
const chunks : AnyChunk [ ] = [ ] ;
138
156
0 commit comments