





















@@ -588,10 +588,17 @@ function isSupersededInstallFailure(
588588return steps.some((candidate) => candidate.name === retryName && candidate.exitCode === 0);
589589}
590590591+function isPreflightCandidateFailure(step: UpdateStepResult): boolean {
592+return /^preflight (?:checkout|deps install(?: \(ignore scripts\))?|build|lint) \(.+\)$/u.test(
593+step.name,
594+);
595+}
596+591597function findBlockingGitFailure(steps: readonly UpdateStepResult[]): UpdateStepResult | undefined {
592598return steps.find(
593599(step, index) =>
594600step.exitCode !== 0 &&
601+!isPreflightCandidateFailure(step) &&
595602!isSupersededInstallFailure(step, steps) &&
596603!isSupersededTargetRefFailure(step, steps.slice(index + 1)),
597604);
@@ -604,9 +611,16 @@ function isSupersededTargetRefFailure(
604611const isTargetRefProbe = step.name.startsWith("git rev-parse ");
605612const isTargetTagFetch = step.name.startsWith("git fetch ") && step.name.includes(" refs/tags/");
606613const isUpstreamProbe = step.name === "upstream check";
607-if (!isTargetRefProbe && !isTargetTagFetch && !isUpstreamProbe) {
614+const isLocalDevBranchProbe = step.name === `git show-ref ${DEV_BRANCH}`;
615+if (!isTargetRefProbe && !isTargetTagFetch && !isUpstreamProbe && !isLocalDevBranchProbe) {
608616return false;
609617}
618+if (isLocalDevBranchProbe) {
619+return followingSteps.some(
620+(candidate) =>
621+candidate.name.startsWith(`git checkout -B ${DEV_BRANCH} `) && candidate.exitCode === 0,
622+);
623+}
610624return followingSteps.some(
611625(candidate) => candidate.name.startsWith("git rev-parse ") && candidate.exitCode === 0,
612626);
@@ -1290,43 +1304,68 @@ export async function runGatewayUpdate(opts: UpdateRunnerOptions = {}): Promise<
12901304}
12911305} else {
12921306await prepareGitMutation();
1307+let checkedOutSelectedSha = false;
12931308if (needsCheckoutMain) {
1309+const localMainStep = await runStep(
1310+step(
1311+`git show-ref ${DEV_BRANCH}`,
1312+["git", "-C", gitRoot, "show-ref", "--verify", `refs/heads/${DEV_BRANCH}`],
1313+gitRoot,
1314+),
1315+);
1316+steps.push(localMainStep);
12941317const failure = await runRequiredGitStep(
1295-`git checkout ${DEV_BRANCH}`,
1296-["git", "-C", gitRoot, "checkout", DEV_BRANCH],
1318+localMainStep.exitCode === 0
1319+ ? `git checkout ${DEV_BRANCH}`
1320+ : `git checkout -B ${DEV_BRANCH} ${selectedSha}`,
1321+localMainStep.exitCode === 0
1322+ ? ["git", "-C", gitRoot, "checkout", DEV_BRANCH]
1323+ : ["git", "-C", gitRoot, "checkout", "-B", DEV_BRANCH, selectedSha],
12971324"checkout-failed",
12981325);
12991326if (failure) {
13001327return failure;
13011328}
1329+checkedOutSelectedSha = localMainStep.exitCode !== 0;
13021330}
1303-const rebaseStep = await runStep(
1304-step("git rebase", ["git", "-C", gitRoot, "rebase", selectedSha], gitRoot),
1305-);
1306-steps.push(rebaseStep);
1307-if (rebaseStep.exitCode !== 0) {
1308-const abortResult = await runCommand(["git", "-C", gitRoot, "rebase", "--abort"], {
1309-cwd: gitRoot,
1310- timeoutMs,
1311-});
1331+if (checkedOutSelectedSha) {
13121332steps.push({
1313-name: "git rebase --abort",
1314-command: "git rebase --abort",
1333+name: "git rebase",
1334+command: `git rebase ${selectedSha}`,
13151335cwd: gitRoot,
13161336durationMs: 0,
1317-exitCode: abortResult.code,
1318-stdoutTail: trimLogTail(abortResult.stdout, MAX_LOG_CHARS),
1319-stderrTail: trimLogTail(abortResult.stderr, MAX_LOG_CHARS),
1337+exitCode: 0,
1338+stdoutTail: `skipped; ${DEV_BRANCH} was created at selected preflight SHA`,
13201339});
1321-return {
1322-status: "error",
1323-mode: "git",
1324-root: gitRoot,
1325-reason: "rebase-failed",
1326-before: { sha: beforeSha, version: beforeVersion },
1327- steps,
1328-durationMs: Date.now() - startedAt,
1329-};
1340+} else {
1341+const rebaseStep = await runStep(
1342+step("git rebase", ["git", "-C", gitRoot, "rebase", selectedSha], gitRoot),
1343+);
1344+steps.push(rebaseStep);
1345+if (rebaseStep.exitCode !== 0) {
1346+const abortResult = await runCommand(["git", "-C", gitRoot, "rebase", "--abort"], {
1347+cwd: gitRoot,
1348+ timeoutMs,
1349+});
1350+steps.push({
1351+name: "git rebase --abort",
1352+command: "git rebase --abort",
1353+cwd: gitRoot,
1354+durationMs: 0,
1355+exitCode: abortResult.code,
1356+stdoutTail: trimLogTail(abortResult.stdout, MAX_LOG_CHARS),
1357+stderrTail: trimLogTail(abortResult.stderr, MAX_LOG_CHARS),
1358+});
1359+return {
1360+status: "error",
1361+mode: "git",
1362+root: gitRoot,
1363+reason: "rebase-failed",
1364+before: { sha: beforeSha, version: beforeVersion },
1365+ steps,
1366+durationMs: Date.now() - startedAt,
1367+};
1368+}
13301369}
13311370}
13321371} else {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。