@@ -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 = parseComparisonInputLine ( ctx ) ;
50
50
51
51
let isDeleted = false ;
52
52
let isNew = false ;
@@ -55,11 +55,18 @@ 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
- 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
+ }
63
70
if ( extHeader . type === ExtendedHeader . RenameFrom ) {
64
71
isRename = true ;
65
72
pathBefore = extHeader . path as string ;
@@ -73,33 +80,30 @@ function parseFileChange(ctx: Context): AnyFileChange | undefined {
73
80
const changeMarkers = parseChangeMarkers ( ctx ) ;
74
81
const chunks = parseChunks ( ctx ) ;
75
82
76
- if ( isDeleted && changeMarkers ) {
83
+ if ( isDeleted && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
77
84
return {
78
85
type : FileType . Deleted ,
79
86
chunks,
80
- path : changeMarkers . deleted ,
87
+ path : chunks [ 0 ] . pathBefore ,
81
88
} ;
82
- } else if (
83
- isDeleted &&
84
- chunks . length &&
85
- chunks [ 0 ] . type === 'BinaryFilesChunk'
86
- ) {
89
+ }
90
+ if ( isDeleted ) {
87
91
return {
88
92
type : FileType . Deleted ,
89
93
chunks,
90
- path : chunks [ 0 ] . pathBefore ,
94
+ path : changeMarkers ?. deleted || pathBefore ,
91
95
} ;
92
- } else if ( isNew && changeMarkers ) {
96
+ } else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
93
97
return {
94
98
type : FileType . Added ,
95
99
chunks,
96
- path : changeMarkers . added ,
100
+ path : chunks [ 0 ] . pathAfter ,
97
101
} ;
98
- } else if ( isNew && chunks . length && chunks [ 0 ] . type === 'BinaryFilesChunk' ) {
102
+ } else if ( isNew ) {
99
103
return {
100
104
type : FileType . Added ,
101
105
chunks,
102
- path : chunks [ 0 ] . pathAfter ,
106
+ path : changeMarkers ?. added || pathAfter ,
103
107
} ;
104
108
} else if ( isRename ) {
105
109
return {
@@ -133,6 +137,20 @@ function isComparisonInputLine(line: string): boolean {
133
137
return line . indexOf ( 'diff' ) === 0 ;
134
138
}
135
139
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
+
136
154
function parseChunks ( context : Context ) : AnyChunk [ ] {
137
155
const chunks : AnyChunk [ ] = [ ] ;
138
156
0 commit comments