Files
upstream-mirror 93ecc1a6f8
Some checks failed
✅ Check / 🔬 ESLint (push) Failing after 21s
✅ Check / 🏷️ Typecheck (push) Failing after 11s
✅ Check / 🔎 Test (push) Failing after 11s
✅ Check / e2e-test (push) Failing after 11s
✅ Check / 🔨 Build (push) Failing after 11s
🚀 Deploy / 🚀 Deploy (doc) (push) Failing after 12s
🚀 Deploy / 🚀 Deploy (demo) (push) Failing after 12s
🚀 Deploy / 🚀 Deploy (supabase) (push) Failing after 18s
snapshot of https://github.com/marmelab/atomic-crm.git (main, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:48:50 +05:00

29 lines
1.2 KiB
JavaScript

// Worktree teardown primitives shared by the cleanup hooks (cleanup-worktree,
// cleanup-session). Mutations live here, kept separate from git.mjs's read-only
// queries. The harness-revert script reuses getWorktreeEntries (read) directly
// but keeps its own mutations because it honours --dry-run.
import { rmSync } from "node:fs";
import { getWorktreeEntries, git } from "./git.mjs";
// Remove one worktree: `git worktree remove --force`, falling back to a plain
// recursive rm when git refuses (e.g. the admin entry is already gone). Callers
// prune afterwards (removeWorktreesUnder does; a lone caller should too).
export function removeWorktree(path) {
if (git(["worktree", "remove", "--force", path]).status !== 0) {
rmSync(path, { recursive: true, force: true });
}
}
// Remove every registered worktree at or under `base`, then prune the admin
// refs. Returns the count removed. The main repo worktree is never under a
// session base, so it is excluded naturally.
export function removeWorktreesUnder(base) {
const under = getWorktreeEntries().filter(
(e) => e.path === base || e.path.startsWith(base + "/"),
);
under.forEach((e) => removeWorktree(e.path));
git(["worktree", "prune"]);
return under.length;
}