fix: git 快进失败时 reset 或 zip 覆盖,更新不再整次失败

This commit is contained in:
叫我小杨同学 committed 2026-09-18 14:18:35 +08:00
1 parent f11078eb1f
commit bea3877f4d
4 files changed
+46 -9

No files matched your search

+35 -6
View File
@@ -386,11 +386,35 @@ export function lastUpdateResult() {
return lastUpdate;
}
function runGit(dir, args, timeout = 20000) {
try {
return execFileSync("git", ["-C", dir, ...args], {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
timeout,
});
} catch (e) {
const detail = [e.stderr, e.stdout, e.message].filter(Boolean).join("\n").trim();
throw new Error(detail || `git ${args.join(" ")}`);
}
}
function gitPull(dir) {
execFileSync("git", ["-C", dir, "pull", "--ff-only", "origin", BRANCH], {
...HIDDEN,
timeout: 60000,
});
try {
runGit(dir, ["pull", "--ff-only", "origin", BRANCH], 60000);
return;
} catch (pullErr) {
try {
runGit(dir, ["fetch", "origin", BRANCH], 60000);
runGit(dir, ["reset", "--hard", `origin/${BRANCH}`], 60000);
return;
} catch (resetErr) {
throw new Error(
`git 更新失败(${dir}):${String(resetErr.message || resetErr).slice(0, 240)};${String(pullErr.message || pullErr).slice(0, 160)}`,
);
}
}
}
function extractZip(zip, dest) {
@@ -443,8 +467,13 @@ export async function applyUpdate(jobs = planUpdates()) {
const vias = new Set();
for (const job of jobs) {
if (job.kind === "git") {
gitPull(job.dir);
vias.add("git");
try {
gitPull(job.dir);
vias.add("git");
continue;
} catch {
zipDirs.push(job.dir);
}
continue;
}
if (job.kind === "dsh") {