UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

87 lines (86 loc) • 2.64 kB
import { createRequire } from "node:module"; //#region src/gateway/repository-publication-restore.generated.worker.mjs const require = createRequire(import.meta.url); process.argv.splice(1, 1); const fs = require("node:fs"); const gitNullPath = process.platform === "win32" ? "NUL" : "/dev/null"; const { spawnSync } = require("node:child_process"); const paths = JSON.parse(fs.readFileSync(0, "utf8")); const cwd = process.cwd(); const env = { ...process.env }; for (const e of Object.keys(env)) if (/^GIT_/i.test(e)) delete env[e]; Object.assign(env, { GIT_CONFIG_GLOBAL: gitNullPath, GIT_CONFIG_SYSTEM: gitNullPath, GIT_CONFIG_KEY_0: "maintenance.auto", GIT_CONFIG_VALUE_0: "false", GIT_CONFIG_KEY_1: "gc.auto", GIT_CONFIG_VALUE_1: "0", GIT_CONFIG_COUNT: "2", GIT_ATTR_NOSYSTEM: "1", GIT_NO_REPLACE_OBJECTS: "1" }); const scopes = ["--local"]; const worktreeConfig = spawnSync("git", [ "config", "--local", "--includes", "--bool", "--default=false", "--get", "extensions.worktreeConfig" ], { cwd, env, timeout: 6e4, maxBuffer: 131072 }); if (worktreeConfig.error || worktreeConfig.status !== 0) throw new Error("Publication workspace has unsupported Git transport configuration"); if (worktreeConfig.stdout.toString("utf8").trim() === "true") scopes.push("--worktree"); for (const e of scopes) { const t = spawnSync("git", [ "config", e, "--includes", "--get-regexp", "^(core\\.(alternaterefscommand|askpass|fsmonitor|gitproxy|sshcommand|worktree)|credential\\..*helper|filter\\..*|http\\..*|include(if)?\\..*|push\\..*|remote\\..*\\.(proxy|receivepack|uploadpack|vcs)|uploadpack\\.packobjectshook|url\\..*\\.(insteadof|pushinsteadof))$" ], { cwd, env, timeout: 6e4, maxBuffer: 131072 }); if (t.error || t.status !== 1 || t.stdout.length) throw new Error("Publication workspace has unsupported Git transport configuration"); } const action = process.argv[1]; if (action !== "add" && action !== "remove") throw new Error("Invalid publication restore operation"); const operation = action === "remove" ? [ "update-index", "--force-remove", "-z", "--stdin" ] : [ "add", "--intent-to-add", "--force", "--pathspec-from-file=-", "--pathspec-file-nul" ]; const result = spawnSync("git", [ "--literal-pathspecs", "-c", "core.hooksPath=" + gitNullPath, "-c", "core.fsmonitor=false", "-c", "core.attributesFile=" + gitNullPath, ...operation ], { env, input: paths.join("\0") + "\0", timeout: 6e4, maxBuffer: 131072 }); if (result.error || result.status !== 0) throw new Error("Repository publication paths could not be restored; retry workspace preparation"); //#endregion export {};