@osdlc/repo-cleaner 0.20.5 → 0.24.0

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +562 -167
  3. package/dist/approval.d.ts +91 -0
  4. package/dist/approval.js +233 -0
  5. package/dist/archive.d.ts +87 -0
  6. package/dist/archive.js +252 -0
  7. package/dist/branches.d.ts +4 -4
  8. package/dist/branches.js +56 -43
  9. package/dist/candidates.d.ts +42 -0
  10. package/dist/candidates.js +42 -0
  11. package/dist/clean.d.ts +66 -70
  12. package/dist/clean.js +386 -218
  13. package/dist/cli.d.ts +16 -10
  14. package/dist/cli.js +273 -102
  15. package/dist/discover.d.ts +28 -7
  16. package/dist/discover.js +185 -42
  17. package/dist/index.d.ts +12 -5
  18. package/dist/index.js +11 -4
  19. package/dist/landing.d.ts +10 -5
  20. package/dist/landing.js +15 -16
  21. package/dist/plan.d.ts +18 -11
  22. package/dist/plan.js +33 -13
  23. package/dist/processes.d.ts +19 -9
  24. package/dist/processes.js +51 -25
  25. package/dist/providers/github.d.ts +21 -3
  26. package/dist/providers/github.js +149 -27
  27. package/dist/providers/gitlab.js +37 -17
  28. package/dist/providers/index.d.ts +1 -1
  29. package/dist/providers/index.js +1 -1
  30. package/dist/providers/types.d.ts +15 -2
  31. package/dist/prs.d.ts +19 -10
  32. package/dist/prs.js +21 -13
  33. package/dist/receipt.d.ts +68 -3
  34. package/dist/receipt.js +30 -3
  35. package/dist/reference.d.ts +1 -1
  36. package/dist/reference.js +99 -51
  37. package/dist/remote-mirror.d.ts +2 -1
  38. package/dist/remote-mirror.js +3 -14
  39. package/dist/render.d.ts +17 -2
  40. package/dist/render.js +81 -14
  41. package/dist/resolve.d.ts +12 -1
  42. package/dist/resolve.js +15 -3
  43. package/dist/scope.d.ts +15 -0
  44. package/dist/scope.js +125 -0
  45. package/dist/size.d.ts +20 -0
  46. package/dist/size.js +34 -0
  47. package/dist/status-line.js +1 -0
  48. package/dist/step-board.js +6 -4
  49. package/dist/sweep.d.ts +50 -18
  50. package/dist/sweep.js +152 -127
  51. package/dist/types.d.ts +89 -10
  52. package/dist/types.js +50 -6
  53. package/dist/util.d.ts +2 -0
  54. package/dist/util.js +25 -0
  55. package/dist/version.generated.d.ts +1 -1
  56. package/dist/version.generated.js +1 -1
  57. package/dist/worktrees.js +87 -11
  58. package/package.json +6 -5
package/dist/prs.d.ts CHANGED
@@ -8,22 +8,23 @@
8
8
  */
9
9
  import type { PrProvider } from './providers/index.ts';
10
10
  import type { ProviderStatus } from './providers/types.ts';
11
- import type { PRInfo, RepoInfo } from './types.ts';
12
- /** Why the provider did not answer, and the words for it. */
11
+ import type { PRInfo } from './types.ts';
12
+ /** Why open pull requests cannot be ruled out, and the words for it. */
13
13
  export interface PrsUnchecked {
14
- kind: 'not-installed' | 'not-signed-in' | 'list-failed';
14
+ kind: 'not-installed' | 'not-signed-in' | 'list-failed' | 'incomplete';
15
15
  /** For a sentence: "`gh` is not installed", "`gh pr list` failed". */
16
16
  why: string;
17
17
  }
18
18
  /**
19
19
  * Why open pull requests cannot be ruled out for this repository, or null
20
- * when the provider answered. A missing or signed-out CLI was never asked, and
21
- * a failed listing answered nothing; either way a remote branch with no known
22
- * PR may still have an open one. Every sentence about a lookup that did not
20
+ * when the provider answered with a whole listing. A missing or signed-out CLI
21
+ * was never asked, a failed listing answered nothing, and an incomplete one
22
+ * left requests out; in each case a remote branch with no known PR may still
23
+ * have an open one. Every sentence about a lookup that did not
23
24
  * answer is built from this one answer.
24
25
  */
25
26
  export declare function prsUnchecked(status: ProviderStatus): PrsUnchecked | null;
26
- /** A provider's answer for one repository: its pull requests, or why there are none to read. */
27
+ /** A provider's answer for one repository: its pull requests, and why any could be missing. */
27
28
  export interface PrLookup {
28
29
  /** Pull requests keyed by head branch; empty when the lookup failed or was not made. */
29
30
  prs: Map<string, PRInfo>;
@@ -32,6 +33,8 @@ export interface PrLookup {
32
33
  * null when it answered, or when it was not asked at all.
33
34
  */
34
35
  error: string | null;
36
+ /** {@link PrListing.incomplete}, passed through; null when the listing is whole. */
37
+ incomplete: string | null;
35
38
  }
36
39
  /**
37
40
  * Every same-repository pull request, keyed by head branch, and why there are
@@ -48,11 +51,17 @@ export interface PrLookup {
48
51
  * null or throws has failed (a repository the signed-in account cannot see, a
49
52
  * forge that is down, output that cannot be read), and `error` says why.
50
53
  * Classification then degrades to git evidence, and the sweep notes it rather
51
- * than losing every row to one listing.
54
+ * than losing every row to one listing. A listing that answered but says it
55
+ * left requests out returns the PRs it read, with `incomplete` saying why.
52
56
  *
57
+ * @param at The repository's root, and what the probe of one remote's
58
+ * provider found (a `RepoInfo` gives its default remote's).
53
59
  * @param provider The provider to ask. It is asked only when it is the one
54
- * `repo.provider` names and that probe found it signed in.
60
+ * `at.provider` names and that probe found it signed in.
55
61
  * @param branch Ask only for PRs whose head is exactly this branch; rows
56
62
  * for any other head are dropped here too.
57
63
  */
58
- export declare function lookupPrs(repo: RepoInfo, provider: PrProvider, branch?: string): PrLookup;
64
+ export declare function lookupPrs(at: {
65
+ root: string;
66
+ provider: ProviderStatus | null;
67
+ }, provider: PrProvider, branch?: string): PrLookup;
package/dist/prs.js CHANGED
@@ -9,9 +9,10 @@
9
9
  import { errorText } from "./util.js";
10
10
  /**
11
11
  * Why open pull requests cannot be ruled out for this repository, or null
12
- * when the provider answered. A missing or signed-out CLI was never asked, and
13
- * a failed listing answered nothing; either way a remote branch with no known
14
- * PR may still have an open one. Every sentence about a lookup that did not
12
+ * when the provider answered with a whole listing. A missing or signed-out CLI
13
+ * was never asked, a failed listing answered nothing, and an incomplete one
14
+ * left requests out; in each case a remote branch with no known PR may still
15
+ * have an open one. Every sentence about a lookup that did not
15
16
  * answer is built from this one answer.
16
17
  */
17
18
  export function prsUnchecked(status) {
@@ -23,6 +24,9 @@ export function prsUnchecked(status) {
23
24
  if (status.listError !== undefined) {
24
25
  return { kind: 'list-failed', why: `\`${status.listing}\` failed` };
25
26
  }
27
+ if (status.incomplete !== undefined) {
28
+ return { kind: 'incomplete', why: `\`${status.listing}\` did not read every ${status.noun}` };
29
+ }
26
30
  return null;
27
31
  }
28
32
  /** Open outranks merged outranks closed, and a newer PR outranks an older. */
@@ -44,33 +48,37 @@ function priority(state) {
44
48
  * null or throws has failed (a repository the signed-in account cannot see, a
45
49
  * forge that is down, output that cannot be read), and `error` says why.
46
50
  * Classification then degrades to git evidence, and the sweep notes it rather
47
- * than losing every row to one listing.
51
+ * than losing every row to one listing. A listing that answered but says it
52
+ * left requests out returns the PRs it read, with `incomplete` saying why.
48
53
  *
54
+ * @param at The repository's root, and what the probe of one remote's
55
+ * provider found (a `RepoInfo` gives its default remote's).
49
56
  * @param provider The provider to ask. It is asked only when it is the one
50
- * `repo.provider` names and that probe found it signed in.
57
+ * `at.provider` names and that probe found it signed in.
51
58
  * @param branch Ask only for PRs whose head is exactly this branch; rows
52
59
  * for any other head are dropped here too.
53
60
  */
54
- export function lookupPrs(repo, provider, branch) {
61
+ export function lookupPrs(at, provider, branch) {
55
62
  const byHead = new Map();
56
- const status = repo.provider;
63
+ const status = at.provider;
57
64
  if (status === null || status.name !== provider.name || !status.authenticated) {
58
- return { prs: byHead, error: null };
65
+ return { prs: byHead, error: null, incomplete: null };
59
66
  }
60
67
  let rows;
61
68
  try {
62
- rows = provider.listPrs(repo.root, status, branch);
69
+ rows = provider.listPrs(at.root, status, branch);
63
70
  }
64
71
  catch (err) {
65
72
  // A bug in the provider is not a listing that failed: let it fail loudly,
66
73
  // as an error on the repository, rather than gate every remote branch.
67
74
  if (err instanceof TypeError || err instanceof ReferenceError)
68
75
  throw err;
69
- return { prs: byHead, error: errorText(err) };
76
+ return { prs: byHead, error: errorText(err), incomplete: null };
70
77
  }
71
78
  if (rows === null)
72
- return { prs: byHead, error: 'the provider gave no reason' };
73
- for (const info of rows) {
79
+ return { prs: byHead, error: 'the provider gave no reason', incomplete: null };
80
+ const incomplete = Array.isArray(rows) ? null : (rows.incomplete ?? null);
81
+ for (const info of Array.isArray(rows) ? rows : rows.prs) {
74
82
  const head = info.headRef;
75
83
  if (!head)
76
84
  continue;
@@ -87,5 +95,5 @@ export function lookupPrs(repo, provider, branch) {
87
95
  byHead.set(head, info);
88
96
  }
89
97
  }
90
- return { prs: byHead, error: null };
98
+ return { prs: byHead, error: null, incomplete };
91
99
  }
package/dist/receipt.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** What a run did, step by step, rewritten after every step. */
2
2
  import { z } from 'zod';
3
3
  /** The receipt format's version, written into every receipt. */
4
- export declare const RECEIPT_VERSION = 2;
4
+ export declare const RECEIPT_VERSION = 3;
5
5
  /**
6
6
  * Why a row did not run:
7
7
  *
@@ -34,12 +34,34 @@ export declare const DroppedSchema: z.ZodObject<{
34
34
  detail: z.ZodString;
35
35
  }, z.core.$strip>;
36
36
  export type Dropped = z.infer<typeof DroppedSchema>;
37
- export declare const STEP_ACTIONS: readonly ["verify-remote", "unlock-worktree", "remove-worktree", "delete-branch", "delete-remote", "prune-worktrees"];
37
+ export declare const STEP_ACTIONS: readonly ["verify-remote", "archive", "unlock-worktree", "remove-worktree", "delete-branch", "delete-remote", "prune-worktrees"];
38
+ /** What an `archive` step pushed: the branch, the commit, and what each parent holds. */
39
+ export declare const ArchiveSchema: z.ZodObject<{
40
+ remote: z.ZodString;
41
+ ref: z.ZodString;
42
+ sha: z.ZodString;
43
+ parents: z.ZodArray<z.ZodObject<{
44
+ parent: z.ZodNumber;
45
+ sha: z.ZodString;
46
+ source: z.ZodString;
47
+ rows: z.ZodArray<z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>>;
48
+ leftOut: z.ZodArray<z.ZodObject<{
49
+ path: z.ZodString;
50
+ reason: z.ZodEnum<{
51
+ secret: "secret";
52
+ excluded: "excluded";
53
+ "too-large": "too-large";
54
+ }>;
55
+ }, z.core.$strip>>;
56
+ }, z.core.$strip>>;
57
+ }, z.core.$strip>;
58
+ export type ArchiveRecord = z.infer<typeof ArchiveSchema>;
38
59
  export declare const StepSchema: z.ZodObject<{
39
60
  repo: z.ZodString;
40
61
  row: z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>;
41
62
  action: z.ZodEnum<{
42
63
  "verify-remote": "verify-remote";
64
+ archive: "archive";
43
65
  "unlock-worktree": "unlock-worktree";
44
66
  "remove-worktree": "remove-worktree";
45
67
  "delete-branch": "delete-branch";
@@ -53,14 +75,35 @@ export declare const StepSchema: z.ZodObject<{
53
75
  "would-run": "would-run";
54
76
  ok: "ok";
55
77
  failed: "failed";
78
+ skipped: "skipped";
56
79
  }>;
57
80
  error: z.ZodNullable<z.ZodString>;
58
81
  verification: z.ZodNullable<z.ZodString>;
59
82
  gone: z.ZodOptional<z.ZodLiteral<true>>;
83
+ archive: z.ZodOptional<z.ZodObject<{
84
+ remote: z.ZodString;
85
+ ref: z.ZodString;
86
+ sha: z.ZodString;
87
+ parents: z.ZodArray<z.ZodObject<{
88
+ parent: z.ZodNumber;
89
+ sha: z.ZodString;
90
+ source: z.ZodString;
91
+ rows: z.ZodArray<z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>>;
92
+ leftOut: z.ZodArray<z.ZodObject<{
93
+ path: z.ZodString;
94
+ reason: z.ZodEnum<{
95
+ secret: "secret";
96
+ excluded: "excluded";
97
+ "too-large": "too-large";
98
+ }>;
99
+ }, z.core.$strip>>;
100
+ }, z.core.$strip>>;
101
+ }, z.core.$strip>>;
102
+ freedBytes: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
60
103
  }, z.core.$strip>;
61
104
  export type Step = z.infer<typeof StepSchema>;
62
105
  export declare const ReceiptSchema: z.ZodObject<{
63
- version: z.ZodLiteral<2>;
106
+ version: z.ZodLiteral<3>;
64
107
  plan: z.ZodString;
65
108
  status: z.ZodEnum<{
66
109
  failed: "failed";
@@ -91,6 +134,7 @@ export declare const ReceiptSchema: z.ZodObject<{
91
134
  row: z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>;
92
135
  action: z.ZodEnum<{
93
136
  "verify-remote": "verify-remote";
137
+ archive: "archive";
94
138
  "unlock-worktree": "unlock-worktree";
95
139
  "remove-worktree": "remove-worktree";
96
140
  "delete-branch": "delete-branch";
@@ -104,10 +148,31 @@ export declare const ReceiptSchema: z.ZodObject<{
104
148
  "would-run": "would-run";
105
149
  ok: "ok";
106
150
  failed: "failed";
151
+ skipped: "skipped";
107
152
  }>;
108
153
  error: z.ZodNullable<z.ZodString>;
109
154
  verification: z.ZodNullable<z.ZodString>;
110
155
  gone: z.ZodOptional<z.ZodLiteral<true>>;
156
+ archive: z.ZodOptional<z.ZodObject<{
157
+ remote: z.ZodString;
158
+ ref: z.ZodString;
159
+ sha: z.ZodString;
160
+ parents: z.ZodArray<z.ZodObject<{
161
+ parent: z.ZodNumber;
162
+ sha: z.ZodString;
163
+ source: z.ZodString;
164
+ rows: z.ZodArray<z.ZodCustom<`worktree:${string}` | `branch:${string}` | `remote:${string}`, `worktree:${string}` | `branch:${string}` | `remote:${string}`>>;
165
+ leftOut: z.ZodArray<z.ZodObject<{
166
+ path: z.ZodString;
167
+ reason: z.ZodEnum<{
168
+ secret: "secret";
169
+ excluded: "excluded";
170
+ "too-large": "too-large";
171
+ }>;
172
+ }, z.core.$strip>>;
173
+ }, z.core.$strip>>;
174
+ }, z.core.$strip>>;
175
+ freedBytes: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
111
176
  }, z.core.$strip>>;
112
177
  }, z.core.$strip>;
113
178
  export type Receipt = z.infer<typeof ReceiptSchema>;
package/dist/receipt.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { z } from 'zod';
3
3
  import { RowIdSchema } from "./plan.js";
4
4
  /** The receipt format's version, written into every receipt. */
5
- export const RECEIPT_VERSION = 2;
5
+ export const RECEIPT_VERSION = 3;
6
6
  /**
7
7
  * Why a row did not run:
8
8
  *
@@ -35,20 +35,39 @@ export const DroppedSchema = z.object({
35
35
  });
36
36
  export const STEP_ACTIONS = [
37
37
  'verify-remote',
38
+ 'archive',
38
39
  'unlock-worktree',
39
40
  'remove-worktree',
40
41
  'delete-branch',
41
42
  'delete-remote',
42
43
  'prune-worktrees',
43
44
  ];
45
+ /** What an `archive` step pushed: the branch, the commit, and what each parent holds. */
46
+ export const ArchiveSchema = z.object({
47
+ remote: z.string(),
48
+ ref: z.string(),
49
+ sha: z.string(),
50
+ /** The archive commit's parents, numbered as git does (`<sha>^2`); parent 1 is the default branch's tip. */
51
+ parents: z.array(z.object({
52
+ parent: z.number().int(),
53
+ sha: z.string(),
54
+ source: z.string(),
55
+ rows: z.array(RowIdSchema),
56
+ leftOut: z.array(z.object({ path: z.string(), reason: z.enum(['secret', 'excluded', 'too-large']) })),
57
+ })),
58
+ });
44
59
  export const StepSchema = z.object({
45
60
  repo: z.string(),
46
- /** The row the step acts on. */
61
+ /** The row the step acts on; an `archive` step names the first row it holds. */
47
62
  row: RowIdSchema,
48
63
  action: z.enum(STEP_ACTIONS),
49
64
  command: z.string(),
50
65
  expectedSha: z.string().nullable(),
51
- result: z.enum(['pending', 'would-run', 'ok', 'failed']),
66
+ /**
67
+ * `skipped`: an earlier step this one depends on failed, so it did not run;
68
+ * `error` names that step.
69
+ */
70
+ result: z.enum(['pending', 'would-run', 'ok', 'failed', 'skipped']),
52
71
  error: z.string().nullable(),
53
72
  verification: z.string().nullable(),
54
73
  /**
@@ -57,6 +76,14 @@ export const StepSchema = z.object({
57
76
  * nothing, and the run summary counts it apart. Absent otherwise.
58
77
  */
59
78
  gone: z.literal(true).optional(),
79
+ /** What an `archive` step pushed; set once it succeeded. */
80
+ archive: ArchiveSchema.optional(),
81
+ /**
82
+ * Bytes a `remove-worktree` step freed: its directory's size on disk (`du`),
83
+ * measured just before the remove. Set once the remove succeeded; null when
84
+ * the measurement failed or timed out. Absent on every other step.
85
+ */
86
+ freedBytes: z.number().int().nonnegative().nullable().optional(),
60
87
  });
61
88
  export const ReceiptSchema = z.object({
62
89
  version: z.literal(RECEIPT_VERSION),
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /** The extended help for each command: its own options, then the shared vocabulary. */
7
7
  export declare const REFERENCE: {
8
- readonly report: string;
8
+ readonly status: string;
9
9
  readonly plan: string;
10
10
  readonly clean: string;
11
11
  readonly cache: "repo-cleaner cache [list | remove <url>... | remove --all]\n Lists or removes the clones kept for remote URL targets. A removed clone is\n cloned again by the next sweep of its URL; a plan that names it cannot run.";
package/dist/reference.js CHANGED
@@ -6,37 +6,59 @@
6
6
  const TARGETS = `Targets
7
7
  A target is what to sweep:
8
8
  a checkout that repository; a linked worktree sweeps the repository it belongs to
9
- a directory every checkout found under it, three levels deep at most
9
+ a directory every checkout found under it, three levels deep at most;
10
+ --max-depth changes that
10
11
  a remote URL its remote branches only, through a clone kept in the cache
11
12
  directory (https://, ssh://, file://, or user@host:path)
12
13
  No target sweeps the directory you are in, read the same way; in a subdirectory
13
14
  the checkout around it tracks, where the search finds no checkout, that checkout.`;
14
- const SWEEP = `Sweep options (the report, plan and clean)
15
- --remote Also judge remote branches. Turns on the network: fetches
16
- each remote first and asks GitHub or GitLab about pull
17
- requests. Slower.
18
- --offline With --remote: do not fetch; judge against the
19
- remote-tracking refs already on disk, remote branches
20
- included, so judging does not contact the remote. Tips can
21
- be stale; clean asks the remote before deleting on it.
22
- Pull requests are still looked up; add --provider none
23
- to judge with no network at all.
24
- --only <kinds> Only these kinds of row: worktree, branch, remote,
25
- comma-separated. Default: worktree,branch, plus remote with
26
- --remote. Naming remote implies --remote.
15
+ const SWEEP = `What to look at (status, plan and clean)
16
+ --local Worktrees and local branches. The default when no scope
17
+ flag is given. No network, unless --fetch.
18
+ --remote Branches on the default remote: origin, else the remote the
19
+ default branch tracks, else the only remote. Fetches it
20
+ first and looks up pull requests.
21
+ --remote=<name> Branches on this remote; --remote='*' is every remote.
22
+ Repeatable, and adds to a bare --remote. Each is fetched,
23
+ and its branches judged against its own default branch.
24
+ --all --local and --remote. With other remotes, write them out:
25
+ --local --remote=upstream.
26
+ --worktrees Only worktrees, of the local rows.
27
+ --branches Only local branches, of the local rows.
28
+ --max-depth <n> How many levels below a directory target a checkout may
29
+ sit and still be found. Default 3, a whole number, 1 or
30
+ more. A search that stops short says how many directories
31
+ it left unopened.
32
+ Scope flags add up: --worktrees --remote is worktrees and the default remote's
33
+ branches.
34
+
35
+ How sure
36
+ --fetch Fetch the default remote before judging local rows.
37
+ --offline No network: no fetch; judge against the remote-tracking
38
+ refs already on disk. Tips can be stale; clean asks the
39
+ remote before deleting on it. Pull requests are still
40
+ looked up; add --provider none for no network at all.
41
+ --against <remote> Judge every row against this remote's default branch, as
42
+ a fork against its parent. Without it, a remote's branches
43
+ are judged against its own default branch, and local rows
44
+ against the default remote's.
45
+ --provider <name> With remote rows: where pull requests come from. auto (by
46
+ each remote's host), github, gitlab, or none to judge on
47
+ git evidence alone.
27
48
  --branch <name|HEAD> Only the rows of one branch: its worktree, its local branch,
28
- and its remote branch with --remote. HEAD is the branch
29
- checked out at the target. Never the default branch.
30
- --against <remote> The remote whose default branch counts as "merged into".
31
- Default: origin, then the first remote.
32
- --provider <name> With --remote: where pull requests come from. auto (by the
33
- remote's host), github, gitlab, or none to judge on git
34
- evidence alone.
49
+ and its remote branches. HEAD is the branch checked out at
50
+ the target. Never a default branch.
51
+
52
+ What is shown
35
53
  --no-progress No progress line on stderr.`;
36
- const REPORT = `The report: repo-cleaner [target...]
54
+ const STATUS = `repo-cleaner status [target...]
37
55
  Deletes nothing. Lists each row with its verdict, why, the risks it carries,
38
56
  and the command that would delete it.
39
- --all Also show keep rows. By default only delete, review and
57
+ --sizes Read each worktree's size on disk (du), list rows largest
58
+ first within each verdict, and total the bytes the delete
59
+ and review rows would free. Slower: it reads every file
60
+ under every worktree. status only; plan and clean refuse it.
61
+ --all-rows Also show keep rows. By default only delete, review and
40
62
  blocked rows are listed. Only with --format text.
41
63
  --format text The report. The default.
42
64
  --format summary Counts per repository: total, merged, delete, prune,
@@ -49,22 +71,33 @@ const PLAN = `repo-cleaner plan [target...]
49
71
  -o, --out <file> Where the plan goes; - (the default) is stdout.`;
50
72
  const CLEAN = `repo-cleaner clean [target...]
51
73
  Sweeps (or reads --plan), checks every row again, shows the steps, asks, then
52
- deletes, compare-and-swap, verifying each step and stopping at the first failure.
53
- Without --pick it runs every row judged delete.
54
- --pick <row> Work on exactly these rows. Narrows the run to them, and opts
55
- in review rows and kept rows with an action (an open pull
56
- request), which never run otherwise. A picked row still
57
- needs --allow for its risks. A blocked row is skipped.
58
- Repeatable.
59
- --spare <row> Leave this row alone, and make sure it is what you saw. A
60
- spared row is not deleted, even if it is judged delete. A
61
- spared remote branch is still checked: if its tip moved or
62
- it is gone since the plan, the run stops before deleting
63
- anything. Sparing a worktree also spares its branch.
64
- Repeatable.
74
+ deletes, compare-and-swap, verifying each step. A failed step skips only the
75
+ steps that depend on it. Every row judged delete runs, and each row picked.
76
+ Ends with what it deleted and the disk space the removed worktrees freed, each
77
+ measured with du just before its removal (freed: 4.2 GB (2 worktrees)); a size
78
+ du could not read makes it "at least". A dry run measures nothing.
79
+ --pick <row> Also run this row: a review row, or a kept row with an
80
+ action (an open pull request), never runs otherwise. A
81
+ picked row still needs --allow for its risks. A blocked
82
+ row is skipped. Repeatable.
83
+ --spare <row|glob> Leave this row, or every row the glob matches, alone. A
84
+ glob matches row names, and a remote branch's name
85
+ without its remote; * stays within a /, ** does not. A
86
+ remote branch spared by name is still checked: if its tip
87
+ moved or it is gone since the plan, the run stops before
88
+ deleting anything. Sparing a worktree also spares its
89
+ branch. Repeatable.
65
90
  --allow <risk> Accept this risk for every row that carries it.
66
91
  --allow <risk>=<row> Accept it for that one row only.
67
- --plan <file|-> Run a saved plan instead of sweeping now (- reads stdin).
92
+ -i, --interactive Choose the rows from a checklist: delete rows ticked,
93
+ review rows not, keep and blocked rows shown but not
94
+ selectable. A ticked row's risks are asked for by name.
95
+ Needs a terminal.
96
+ --archive Push unlanded work to an archive branch on the default
97
+ remote before deleting; then --allow discard-archived
98
+ stands for abandon-unmerged and discard-changes.
99
+ --archive-exclude <glob> With --archive, leave these files out of a snapshot.
100
+ --plan <file|-> Clean a saved plan instead of looking now (- reads stdin).
68
101
  Rows whose evidence changed since the plan are dropped.
69
102
  -y, --yes Do not ask. Without it, and with no terminal to ask on,
70
103
  clean refuses.
@@ -102,6 +135,10 @@ Risks (approve each by name with --allow)
102
135
  (or its submodules') commits and stashes that no remote has.
103
136
  discard-changes Uncommitted or untracked files in the worktree or any of its
104
137
  submodules.
138
+ discard-archived With --archive, stands for abandon-unmerged and discard-changes on
139
+ a row whose work the archive holds. Files the snapshot leaves out
140
+ (secret-shaped, --archive-exclude, over 10 MiB) keep discard-changes;
141
+ a worktree's submodule work keeps both risks.
105
142
  confirm-open-pr The branch has an open pull request, or open pull requests could
106
143
  not be checked (the CLI is missing or signed out, or the listing
107
144
  failed); deleting the remote branch closes it.
@@ -112,41 +149,52 @@ const CONFLICTS = `Refused before anything is deleted (exit 2)
112
149
  would have no effect. Most are refused before anything is swept; a row named
113
150
  two ways (a bare name and its id), and an --allow for a row, are checked
114
151
  against the plan, after the sweep.
152
+ no phase named: the bare command explains the phases
153
+ a target that is no directory but a remote's name: write --remote=<name>
154
+ --all with --remote=<name>
115
155
  the same row in --pick and --spare
116
- --allow <risk>=<row> for a spared row, or for a row outside --pick
117
- a picked or spared row of a kind --only leaves out
156
+ --allow <risk>=<row> for a spared row
157
+ -i with --pick, or with --plan -
158
+ a picked or spared row of a kind the scope leaves out
118
159
  a picked or spared row that is not one of --branch's rows
119
- --branch with more than one target, or with a remote URL, or the default branch
120
- --plan with targets or sweep options: the plan already fixed them
160
+ --branch with more than one target, or with a remote URL, or a default branch
161
+ --plan with targets, scope flags or sweep options: the plan already fixed them
121
162
  --plan - without --yes or --dry-run: stdin carries the plan, so nothing can ask
122
163
  --yes with --dry-run
123
164
  --receipt with --dry-run
124
- --offline or --provider without --remote
125
- --remote with an --only that leaves remote out
126
- a remote URL target with --only worktree or --only branch, with --offline, or
127
- mixed with checkout targets
128
- --all with any --format but text
165
+ --fetch with --offline; --fetch with remote rows only
166
+ --offline or --provider without remote rows
167
+ a remote URL target with --worktrees or --branches, with --offline, or mixed
168
+ with checkout targets
169
+ --all-rows with any --format but text
170
+ --sizes with plan or clean: it is a status flag
129
171
 
130
172
  Refused after the sweep, before deleting (exit 1)
131
173
  a picked, spared or allowed row the plan does not have
132
174
  a row name that matches rows in more than one repository
133
175
  a spared remote branch that moved since the plan, or that the re-check no longer finds
134
176
 
177
+ A repository that cannot be read is an error row, and the rest are swept
178
+ a remote it does not have, or several remotes and none of them the default
179
+ --against a remote it does not have
180
+ --provider github or gitlab over remotes on different kinds of host
181
+
135
182
  Allowed, because nothing contradicts
136
183
  the same row picked twice: it runs once
137
184
  --allow <risk> with --allow <risk>=<row>: the broader one covers it
138
185
  --allow for a risk no row that runs carries: the preview lists it as unused
139
186
  picking a blocked or keep row: it is skipped and shown with the reason
140
- --only remote without --remote: asking for remote branches implies the network`;
187
+ a --spare glob that matches nothing`;
141
188
  const EXIT = `Exit codes
142
- 0 swept; or clean ran, was declined, or had nothing to do
189
+ 0 looked or saved; or clean ran, was declined, or had nothing to do
143
190
  1 failed against the state it found: an unreadable plan, a row not in it
144
- 2 cannot run as typed: an unknown flag, a malformed row, a refused combination
191
+ 2 cannot run as typed: no phase named, an unknown flag, a malformed row, a
192
+ refused combination
145
193
  10 no target named a repository
146
- 11 clean stopped at a failed step; the receipt says which`;
194
+ 11 clean had a failed step; the receipt says which, and which steps it skipped`;
147
195
  /** The extended help for each command: its own options, then the shared vocabulary. */
148
196
  export const REFERENCE = {
149
- report: [TARGETS, SWEEP, REPORT, WORDS, CONFLICTS, EXIT].join('\n\n'),
197
+ status: [TARGETS, SWEEP, STATUS, WORDS, CONFLICTS, EXIT].join('\n\n'),
150
198
  plan: [TARGETS, SWEEP, PLAN, WORDS, EXIT].join('\n\n'),
151
199
  clean: [TARGETS, SWEEP, CLEAN, WORDS, CONFLICTS, EXIT].join('\n\n'),
152
200
  cache: CACHE,
@@ -59,7 +59,7 @@ export interface CachedMirror {
59
59
  dir: string;
60
60
  /** The URL it was cloned from, credentials removed; null when there is none to read. */
61
61
  url: string | null;
62
- /** Bytes on disk, every file under the directory counted. */
62
+ /** Bytes on disk under the directory, as `du` counts them; 0 when `du` could not say. */
63
63
  bytes: number;
64
64
  /** A clone left behind by a run that stopped before it finished. */
65
65
  partial: boolean;
@@ -69,6 +69,7 @@ export interface CachedMirror {
69
69
  /** Every entry under `cacheDir`, sorted by directory; none when the cache does not exist. */
70
70
  export declare function listMirrors(cacheDir: string, opts?: {
71
71
  git?: CommandRunner | undefined;
72
+ du?: CommandRunner | undefined;
72
73
  }): CachedMirror[];
73
74
  /**
74
75
  * The mirror directory `url` would use under `cacheDir`, when there is one;
@@ -13,11 +13,12 @@
13
13
  * date.
14
14
  */
15
15
  import { createHash } from 'node:crypto';
16
- import { existsSync, lstatSync, mkdirSync, readdirSync, renameSync, rmSync } from 'node:fs';
16
+ import { existsSync, mkdirSync, readdirSync, renameSync, rmSync } from 'node:fs';
17
17
  import { dirname, join } from 'node:path';
18
18
  import { systemDirs } from '@osdlc/cli-tool';
19
19
  import { Git, parseRemoteRepo } from '@osdlc/typed-git';
20
20
  import { VENDOR_DIRS } from "./devlink.js";
21
+ import { sizeOf } from "./size.js";
21
22
  /** A remote URL that cannot be mirrored, or a mirror that cannot be made or reused. */
22
23
  export class RemoteMirrorError extends Error {
23
24
  constructor(message) {
@@ -124,18 +125,6 @@ export function ensureMirror(url, cacheDir, opts = {}) {
124
125
  return dir;
125
126
  }
126
127
  const PARTIAL = /\.partial-\d+$/;
127
- /** Bytes under `path`, symlinks counted as themselves, not followed. */
128
- function sizeOf(path) {
129
- const stat = lstatSync(path, { throwIfNoEntry: false });
130
- if (stat === undefined)
131
- return 0;
132
- if (!stat.isDirectory())
133
- return stat.size;
134
- let total = 0;
135
- for (const name of readdirSync(path))
136
- total += sizeOf(join(path, name));
137
- return total;
138
- }
139
128
  /** Every entry under `cacheDir`, sorted by directory; none when the cache does not exist. */
140
129
  export function listMirrors(cacheDir, opts = {}) {
141
130
  if (!existsSync(cacheDir))
@@ -146,7 +135,7 @@ export function listMirrors(cacheDir, opts = {}) {
146
135
  .sort()
147
136
  .map((name) => {
148
137
  const dir = join(cacheDir, name);
149
- const bytes = sizeOf(dir);
138
+ const bytes = sizeOf(dir, { du: opts.du }) ?? 0;
150
139
  if (PARTIAL.test(name))
151
140
  return { dir, url: null, bytes, partial: true, problem: null };
152
141
  const problem = mirrorProblem(dir, undefined, opts);
package/dist/render.d.ts CHANGED
@@ -72,10 +72,20 @@ export interface RunSummary {
72
72
  pruned: number;
73
73
  /** Dropped rows by reason. */
74
74
  dropped: Record<string, number>;
75
- /** Steps that failed: 0 or 1, since the first failure stops the run. */
75
+ succeeded: number;
76
76
  failed: number;
77
- /** Row steps never reached because a step failed. */
77
+ /** Steps not run because a step they depend on failed. */
78
+ skipped: number;
79
+ /** Row steps never reached because a spared tip check failed and stopped the run. */
78
80
  notRun: number;
81
+ /**
82
+ * Bytes the removed worktrees took on disk, each measured just before its
83
+ * removal: the `freedBytes` of every `remove-worktree` step that ran `ok`.
84
+ * 0 in a preview, which measures nothing.
85
+ */
86
+ freedBytes: number;
87
+ /** Removed worktrees whose size could not be read, so `freedBytes` leaves them out. */
88
+ unmeasured: number;
79
89
  }
80
90
  /** Count what `steps` did and `dropped` left out. A preview's `would-run` steps count as done. */
81
91
  export declare function summarizeRun(r: {
@@ -84,6 +94,11 @@ export declare function summarizeRun(r: {
84
94
  }): RunSummary;
85
95
  /** Rows a run deletes or prunes, which is what a person is asked to approve. */
86
96
  export declare function rowsActedOn(summary: RunSummary): number;
97
+ /**
98
+ * What a run's removed worktrees freed, as `freed: 4.2 GB (2 worktrees)`, or
99
+ * null when it removed none.
100
+ */
101
+ export declare function renderFreed(s: RunSummary): string | null;
87
102
  /** The closing lines of a run or preview: what it deleted, skipped and could not finish. */
88
103
  export declare function renderRunSummary(r: {
89
104
  steps: readonly Step[];