refactor: extract merge-state cleanup helper in reconcileMergeState
The same ~20-line cleanup sequence (merge abort / squash msg unlink / hard reset) appeared twice in reconcileMergeState(). Extract into a private abortAndResetMerge() helper to eliminate the duplication. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ef5006e16d
commit
0aa7490bc6
1 changed files with 31 additions and 36 deletions
|
|
@ -515,6 +515,35 @@ export function diagnoseExpectedArtifact(
|
|||
|
||||
// ─── Merge State Reconciliation ───────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Best-effort abort of a pending merge/squash and hard-reset to HEAD.
|
||||
* Handles both real merges (MERGE_HEAD) and squash merges (SQUASH_MSG).
|
||||
*/
|
||||
function abortAndResetMerge(
|
||||
basePath: string,
|
||||
hasMergeHead: boolean,
|
||||
squashMsgPath: string,
|
||||
): void {
|
||||
if (hasMergeHead) {
|
||||
try {
|
||||
nativeMergeAbort(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
} else if (squashMsgPath) {
|
||||
try {
|
||||
unlinkSync(squashMsgPath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
}
|
||||
try {
|
||||
nativeResetHard(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect leftover merge state from a prior session and reconcile it.
|
||||
* If MERGE_HEAD or SQUASH_MSG exists, check whether conflicts are resolved.
|
||||
|
|
@ -571,24 +600,7 @@ export function reconcileMergeState(
|
|||
}
|
||||
}
|
||||
if (!resolved) {
|
||||
if (hasMergeHead) {
|
||||
try {
|
||||
nativeMergeAbort(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
} else if (hasSquashMsg) {
|
||||
try {
|
||||
unlinkSync(squashMsgPath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
}
|
||||
try {
|
||||
nativeResetHard(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
abortAndResetMerge(basePath, hasMergeHead, squashMsgPath);
|
||||
ctx.ui.notify(
|
||||
"Detected leftover merge state — auto-resolve failed, cleaned up. Re-deriving state.",
|
||||
"warning",
|
||||
|
|
@ -596,24 +608,7 @@ export function reconcileMergeState(
|
|||
}
|
||||
} else {
|
||||
// Code conflicts present — abort and reset
|
||||
if (hasMergeHead) {
|
||||
try {
|
||||
nativeMergeAbort(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
} else if (hasSquashMsg) {
|
||||
try {
|
||||
unlinkSync(squashMsgPath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
}
|
||||
try {
|
||||
nativeResetHard(basePath);
|
||||
} catch {
|
||||
/* best-effort */
|
||||
}
|
||||
abortAndResetMerge(basePath, hasMergeHead, squashMsgPath);
|
||||
ctx.ui.notify(
|
||||
"Detected leftover merge state with unresolved conflicts — cleaned up. Re-deriving state.",
|
||||
"warning",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue