Skip to content

Commit b4932d5

Browse files
committed
fix: handle leftover prev amends if no further rebase happened
Signed-off-by: Kipras Melnikovas <[email protected]>
1 parent b76f275 commit b4932d5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

reducePath.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export function combineRewrittenLists(rewrittenListFileContent: string): Combine
112112
let prev : RewrittenListBlockAmend[] = []
113113
let mergedReducedRewrittenLists: RewrittenListBlockRebase[] = []
114114

115+
let lastRebaseList: RewrittenListBlockRebase | null = null
116+
115117
for (const list of rewrittenLists) {
116118
if (list.type === "amend") {
117119
prev.push(list)
@@ -278,10 +280,35 @@ export function combineRewrittenLists(rewrittenListFileContent: string): Combine
278280
prev = []
279281
reducePath(list.mapping)
280282
mergedReducedRewrittenLists.push(list)
283+
lastRebaseList = list
281284
} else {
282285
throw new Error(`invalid list type (got "${(list as any).type}")`)
283286
}
284287
}
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+
285312
/**
286313
* TODO handle multiple rebases
287314
* or, multiple separate files for each new rebase,

0 commit comments

Comments
 (0)