File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,8 @@ export function combineRewrittenLists(rewrittenListFileContent: string): Combine
112
112
let prev : RewrittenListBlockAmend [ ] = [ ]
113
113
let mergedReducedRewrittenLists : RewrittenListBlockRebase [ ] = [ ]
114
114
115
+ let lastRebaseList : RewrittenListBlockRebase | null = null
116
+
115
117
for ( const list of rewrittenLists ) {
116
118
if ( list . type === "amend" ) {
117
119
prev . push ( list )
@@ -278,10 +280,35 @@ export function combineRewrittenLists(rewrittenListFileContent: string): Combine
278
280
prev = [ ]
279
281
reducePath ( list . mapping )
280
282
mergedReducedRewrittenLists . push ( list )
283
+ lastRebaseList = list
281
284
} else {
282
285
throw new Error ( `invalid list type (got "${ ( list as any ) . type } ")` )
283
286
}
284
287
}
288
+
289
+ if ( prev . length ) {
290
+ /**
291
+ * likely a rebase happenend first,
292
+ * it was not `--apply`ied,
293
+ * and then a `commit --amend` happend.
294
+ *
295
+ * if we don't handle this case,
296
+ * the changes done in the `--amend`
297
+ * would be lost.
298
+ */
299
+
300
+ if ( ! lastRebaseList ) {
301
+ throw new Error ( `NOT IMPLEMENTED - found "amend"(s) in rewritten-list, but did not find any "rebase"(s).` )
302
+ }
303
+
304
+ for ( const amend of prev ) {
305
+ Object . assign ( lastRebaseList . mapping , amend . mapping )
306
+ reducePath ( lastRebaseList . mapping )
307
+ }
308
+
309
+ prev = [ ]
310
+ }
311
+
285
312
/**
286
313
* TODO handle multiple rebases
287
314
* or, multiple separate files for each new rebase,
You can’t perform that action at this time.
0 commit comments