Skip to content

Commit 5ec72f6

Browse files
committed
fix: abort rebase on failure in LocalRuntime
execAsync throws on non-zero exit, so the rebase abort was never reached when git rebase failed. Wrap in nested try-catch to ensure we always clean up stuck rebases. Addresses code review feedback: #800
1 parent 5f61c90 commit 5ec72f6

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/node/runtime/LocalRuntime.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,24 @@ export class LocalRuntime implements Runtime {
398398
initLogger.logStep("Rebasing on latest...");
399399

400400
// Attempt rebase on origin/<trunkBranch>
401-
using rebaseProc = execAsync(`git -C "${workspacePath}" rebase "origin/${trunkBranch}"`);
402-
const rebaseResult = await rebaseProc.result;
403-
404-
if (rebaseResult.stderr?.includes("CONFLICT")) {
405-
// Rebase has conflicts - abort and warn
406-
using abortProc = execAsync(`git -C "${workspacePath}" rebase --abort`);
407-
await abortProc.result;
408-
initLogger.logStderr(
409-
"Warning: Rebase failed due to conflicts, continuing with current state"
410-
);
411-
} else {
401+
// execAsync throws on non-zero exit, so we catch rebase failures separately
402+
try {
403+
using rebaseProc = execAsync(`git -C "${workspacePath}" rebase "origin/${trunkBranch}"`);
404+
await rebaseProc.result;
412405
initLogger.logStep("Rebased on latest successfully");
406+
} catch (rebaseError) {
407+
// Rebase failed (conflicts or other error) - abort and warn
408+
try {
409+
using abortProc = execAsync(`git -C "${workspacePath}" rebase --abort`);
410+
await abortProc.result;
411+
} catch {
412+
// Abort may fail if rebase wasn't in progress; ignore
413+
}
414+
const errorMsg = getErrorMessage(rebaseError);
415+
initLogger.logStderr(`Warning: Rebase failed (${errorMsg}), continuing with current state`);
413416
}
414417
} catch (error) {
415-
// Non-fatal: log warning and continue
418+
// Non-fatal: log warning and continue (fetch failed)
416419
const errorMsg = getErrorMessage(error);
417420
initLogger.logStderr(`Warning: Failed to pull latest (${errorMsg}), continuing anyway`);
418421
}

0 commit comments

Comments
 (0)