benignswarm 0.12.29 → 0.12.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/watch.js +2 -2
- package/dist/commands/worktrees.js +2 -2
- package/dist/git.js +21 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/watch.js
CHANGED
|
@@ -7,7 +7,7 @@ import { loadAgent, resolveAgentName } from "../config.js";
|
|
|
7
7
|
import { Client } from "../client.js";
|
|
8
8
|
import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
|
|
9
9
|
import { scanProject, unitWorktrees } from "./worktrees.js";
|
|
10
|
-
import { pruneReport,
|
|
10
|
+
import { pruneReport, removePrunable } from "../git.js";
|
|
11
11
|
import { CliError } from "../errors.js";
|
|
12
12
|
import { acquireWatchLock } from "../lock.js";
|
|
13
13
|
import { gatherUpdates } from "./hook.js";
|
|
@@ -89,7 +89,7 @@ export async function watch(p, out) {
|
|
|
89
89
|
// closed; never one a unit is still being worked in (it may have no commits yet).
|
|
90
90
|
const units = await unitWorktrees(scanCreds, scanCreds.project);
|
|
91
91
|
for (const c of pruneReport(process.cwd(), units.closed, units.active).prunable) {
|
|
92
|
-
const res =
|
|
92
|
+
const res = removePrunable(c);
|
|
93
93
|
log(res.removed ? `pruned merged worktree ${c.path}${c.branch ? ` (${c.branch})` : ""}` : `kept ${c.path}: ${res.reason}`);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -4,7 +4,7 @@ import { Client } from "../client.js";
|
|
|
4
4
|
import { loadAgent, resolveAgentName } from "../config.js";
|
|
5
5
|
import { CliError } from "../errors.js";
|
|
6
6
|
import { spawnSync } from "node:child_process";
|
|
7
|
-
import { archiveWorktreeChanges, defaultMachine, scanWorktrees, pruneReport,
|
|
7
|
+
import { archiveWorktreeChanges, defaultMachine, scanWorktrees, pruneReport, removePrunable } from "../git.js";
|
|
8
8
|
import { table } from "../output.js";
|
|
9
9
|
const CLOSED = ["done", "abandoned", "superseded"];
|
|
10
10
|
/**
|
|
@@ -87,7 +87,7 @@ export async function worktrees(p, out) {
|
|
|
87
87
|
const removed = [];
|
|
88
88
|
const kept = [];
|
|
89
89
|
for (const c of candidates) {
|
|
90
|
-
const r =
|
|
90
|
+
const r = removePrunable(c);
|
|
91
91
|
if (r.removed)
|
|
92
92
|
removed.push(c.path);
|
|
93
93
|
else
|
package/dist/git.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, realpathSync, rmSync } from "node:fs";
|
|
1
|
+
import { copyFileSync, existsSync, readdirSync, realpathSync, rmSync } from "node:fs";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
import { hostname } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
function git(args, cwd) {
|
|
6
|
-
|
|
6
|
+
// Large enough for `git status` on a big repo with every file changed (ester: 226k files, 25 MB);
|
|
7
|
+
// the 1 MB default made such a worktree unreadable rather than dirty.
|
|
8
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 512 * 1024 * 1024 });
|
|
7
9
|
if (r.status !== 0)
|
|
8
10
|
return null;
|
|
9
11
|
return r.stdout.trim();
|
|
@@ -53,7 +55,8 @@ export function scanWorktrees(cwd = process.cwd()) {
|
|
|
53
55
|
const head = git(["rev-parse", "--short", "HEAD"], p);
|
|
54
56
|
const status = git(["status", "--porcelain"], p);
|
|
55
57
|
const f = head ? mergeFacts(p, p) : { base: null, merged: null, ahead: null };
|
|
56
|
-
|
|
58
|
+
const empty = existsSync(p) && readdirSync(p).every((e) => e === ".git");
|
|
59
|
+
return { path: p, branch, head, dirty: status === null ? null : status.length > 0, base: f.base, merged: f.merged, ahead: f.ahead, empty };
|
|
57
60
|
});
|
|
58
61
|
return { repo, worktrees };
|
|
59
62
|
}
|
|
@@ -244,6 +247,12 @@ export function pruneReport(cwd = process.cwd(), closedUnitPaths = new Map(), ac
|
|
|
244
247
|
continue;
|
|
245
248
|
}
|
|
246
249
|
const closedNote = closedUnitPaths.get(realpathOrSelf(w.path));
|
|
250
|
+
// Nothing but .git: a checkout that never happened. There are no files to lose, and archiving
|
|
251
|
+
// it would record "every file deleted". The branch is untouched.
|
|
252
|
+
if (w.empty) {
|
|
253
|
+
prunable.push({ path: w.path, branch: w.branch, empty: true, why: `empty checkout (an interrupted git worktree add)${closedNote ? `, ${closedNote}` : ""}` });
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
247
256
|
if (w.dirty !== false) {
|
|
248
257
|
kept.push({ path: w.path, branch: w.branch, reason: `${w.dirty === null ? "cannot read its status" : "uncommitted changes"}${closedNote ? ` (${closedNote}${w.dirty ? "; --archive saves them to a branch and removes it" : ""})` : ""}`, ...(closedNote && w.dirty === true ? { archivable: closedNote } : {}) });
|
|
249
258
|
continue;
|
|
@@ -336,6 +345,15 @@ export function archiveWorktreeChanges(path, name, message) {
|
|
|
336
345
|
rmSync(tmp.startsWith("/") ? tmp : join(path, tmp), { force: true });
|
|
337
346
|
}
|
|
338
347
|
}
|
|
348
|
+
/** Removes a prune candidate: an empty checkout (re-checked here) by force, anything else only when clean. */
|
|
349
|
+
export function removePrunable(c, cwd = process.cwd()) {
|
|
350
|
+
if (!c.empty)
|
|
351
|
+
return removeWorktreeIfClean(c.path, cwd);
|
|
352
|
+
if (!existsSync(c.path) || !readdirSync(c.path).every((e) => e === ".git"))
|
|
353
|
+
return { removed: false, reason: "no longer an empty checkout" };
|
|
354
|
+
const r = spawnSync("git", ["worktree", "remove", "--force", c.path], { cwd, encoding: "utf8" });
|
|
355
|
+
return r.status === 0 ? { removed: true } : { removed: false, reason: (r.stderr || r.stdout).trim() };
|
|
356
|
+
}
|
|
339
357
|
export function removeWorktreeIfClean(path, cwd = process.cwd()) {
|
|
340
358
|
const status = git(["status", "--porcelain"], path);
|
|
341
359
|
if (status === null)
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.30";
|