{"draft":null,"from":41,"to":42,"files":[{"path":"client/launch.mjs","added":52,"removed":12,"diff":"--- a/client/launch.mjs\n+++ b/client/launch.mjs\n@@ -24,7 +24,7 @@\n import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n import { createRequire } from \"node:module\";\n import { homedir } from \"node:os\";\n-import { dirname, join } from \"node:path\";\n+import { dirname, join, resolve } from \"node:path\";\n import { fileURLToPath, pathToFileURL } from \"node:url\";\n \n const repo = dirname(dirname(fileURLToPath(import.meta.url)));\n@@ -38,29 +38,69 @@\n /** Set by the bundle's first line: an error after it came from the command, so it's never run again. */\n const STARTED = \"__absoBundleStarted\";\n \n+/**\n+ * The checkout's git folders: its own (HEAD) and the shared one (refs, info/exclude). They are the same\n+ * folder in a plain clone; in a worktree .git is a file naming its own folder, which names the shared one.\n+ */\n+function gitDirs(root = repo) {\n+\tconst dot = join(root, \".git\");\n+\ttry {\n+\t\tif (statSync(dot).isDirectory()) return { own: dot, common: dot };\n+\t\tconst own = resolve(\n+\t\t\troot,\n+\t\t\treadFileSync(dot, \"utf8\")\n+\t\t\t\t.trim()\n+\t\t\t\t.replace(/^gitdir:\\s*/, \"\"),\n+\t\t);\n+\t\tlet common = own;\n+\t\ttry {\n+\t\t\tcommon = resolve(own, readFileSync(join(own, \"commondir\"), \"utf8\").trim());\n+\t\t} catch {}\n+\t\treturn { own, common };\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n /** The checkout's commit, read from .git without running git; undefined if it can't be read. */\n function headCommit(root = repo) {\n+\tconst dirs = gitDirs(root);\n+\tif (!dirs) return undefined;\n \ttry {\n-\t\tconst head = readFileSync(join(root, \".git\", \"HEAD\"), \"utf8\").trim();\n+\t\tconst head = readFileSync(join(dirs.own, \"HEAD\"), \"utf8\").trim();\n \t\tif (!head.startsWith(\"ref:\")) return head;\n \t\tconst ref = head.slice(4).trim();\n-\t\ttry {\n-\t\t\treturn readFileSync(join(root, \".git\", ...ref.split(\"/\")), \"utf8\").trim();\n-\t\t} catch {\n-\t\t\tconst line = readFileSync(join(root, \".git\", \"packed-refs\"), \"utf8\")\n-\t\t\t\t.split(\"\\n\")\n-\t\t\t\t.find((l) => l.endsWith(` ${ref}`));\n-\t\t\treturn line?.split(\" \")[0];\n+\t\tfor (const dir of [dirs.own, dirs.common]) {\n+\t\t\ttry {\n+\t\t\t\treturn readFileSync(join(dir, ...ref.split(\"/\")), \"utf8\").trim();\n+\t\t\t} catch {}\n \t\t}\n+\t\tconst line = readFileSync(join(dirs.common, \"packed-refs\"), \"utf8\")\n+\t\t\t.split(\"\\n\")\n+\t\t\t.find((l) => l.endsWith(` ${ref}`));\n+\t\treturn line?.split(\" \")[0];\n \t} catch {\n \t\treturn undefined;\n \t}\n }\n \n-/** Runs fn under a lock folder; a lock older than 10 minutes is a dead run's and is cleared. */\n+/**\n+ * Runs fn under a lock folder, or not at all when another run holds it. A lock older than 10 minutes is a\n+ * dead run's: it is renamed aside before it's removed, so of two runs that find it stale only one takes it\n+ * over, and one that renamed away a lock taken over a moment ago puts it back.\n+ */\n function locked(lock, fn) {\n+\tconst stale = (path) => Date.now() - statSync(path).mtimeMs > 10 * 60 * 1000;\n \ttry {\n-\t\tif (Date.now() - statSync(lock).mtimeMs > 10 * 60 * 1000) rmSync(lock, { recursive: true, force: true });\n+\t\tif (stale(lock)) {\n+\t\t\tconst aside = `${lock}.${process.pid}.stale`;\n+\t\t\trenameSync(lock, aside);\n+\t\t\tif (stale(aside)) rmSync(aside, { recursive: true, force: true });\n+\t\t\telse {\n+\t\t\t\trenameSync(aside, lock);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n \t} catch {}\n \ttry {\n \t\tmkdirSync(lock);\n@@ -124,7 +164,7 @@\n \t} catch {\n \t\treturn;\n \t}\n-\tconst exclude = join(repo, \".git\", \"info\", \"exclude\");\n+\tconst exclude = join(gitDirs()?.common ?? join(repo, \".git\"), \"info\", \"exclude\");\n \ttry {\n \t\tif (!readFileSync(exclude, \"utf8\").split(/\\r?\\n/).includes(\"client/dist/\"))\n \t\t\tappendFileSync(exclude, \"\\nclient/dist/\\n\");"}],"unmatched":[]}