fix(FN-3842): treat already-merged branch as finalize success

This commit is contained in:
Fusion
2026-05-09 08:56:18 -07:00
committed by gsxdsm
parent a4f9f9f52a
commit f0913ede7c
2 changed files with 63 additions and 0 deletions

View File

@@ -2733,6 +2733,9 @@ export async function commitOrAmendMergeWithFixes(
` diffStat(preAttemptHeadSha..branch)\n${diffStatSummary || " <empty>"}`;
mergerLog.warn(diagnostics);
// FN-3842 ordering: trailer short-circuit first (this task already on
// HEAD), then ancestor short-circuit (branch already reachable from
// integration target via a different commit path), then squash-restore.
if (trailerOnHead) {
mergerLog.log(
`${taskId}: HEAD already carries Fusion-Task-Id trailer — treating in-merge fix finalize as no-op success`,
@@ -2740,6 +2743,23 @@ export async function commitOrAmendMergeWithFixes(
return { ok: true, reason: "head-task-trailer" };
}
let branchAlreadyOnIntegrationTarget = false;
try {
await execAsync(`git merge-base --is-ancestor ${branchTip} ${preAttemptHeadSha}`, {
cwd: rootDir,
encoding: "utf-8",
});
branchAlreadyOnIntegrationTarget = true;
} catch {
branchAlreadyOnIntegrationTarget = false;
}
if (branchAlreadyOnIntegrationTarget) {
mergerLog.log(
`${taskId}: branch tip ${branchTip} is already ancestor of integration target ${preAttemptHeadSha} — treating finalize as already-merged success`,
);
return { ok: true, reason: "branch-already-merged" };
}
// No commit and no staged content can still be recoverable when the
// in-merge fix path cleared the previous squash index state. Rebuild the
// squash from branch -> preAttemptHeadSha and continue normally.