@osdlc/repo-cleaner 0.20.5 → 0.22.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.
- package/CHANGELOG.md +64 -0
- package/README.md +545 -165
- package/dist/approval.d.ts +91 -0
- package/dist/approval.js +233 -0
- package/dist/archive.d.ts +87 -0
- package/dist/archive.js +252 -0
- package/dist/branches.d.ts +4 -4
- package/dist/branches.js +56 -43
- package/dist/clean.d.ts +30 -70
- package/dist/clean.js +251 -197
- package/dist/cli.d.ts +16 -10
- package/dist/cli.js +252 -103
- package/dist/discover.d.ts +28 -7
- package/dist/discover.js +185 -42
- package/dist/index.d.ts +6 -3
- package/dist/index.js +5 -2
- package/dist/landing.d.ts +10 -5
- package/dist/landing.js +15 -16
- package/dist/plan.d.ts +18 -11
- package/dist/plan.js +33 -13
- package/dist/processes.d.ts +19 -9
- package/dist/processes.js +51 -25
- package/dist/providers/github.d.ts +21 -3
- package/dist/providers/github.js +149 -27
- package/dist/providers/gitlab.js +37 -17
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/types.d.ts +15 -2
- package/dist/prs.d.ts +19 -10
- package/dist/prs.js +21 -13
- package/dist/receipt.d.ts +68 -3
- package/dist/receipt.js +30 -3
- package/dist/reference.d.ts +1 -1
- package/dist/reference.js +93 -50
- package/dist/remote-mirror.d.ts +2 -1
- package/dist/remote-mirror.js +3 -14
- package/dist/render.d.ts +17 -2
- package/dist/render.js +80 -13
- package/dist/scope.d.ts +15 -0
- package/dist/scope.js +125 -0
- package/dist/size.d.ts +20 -0
- package/dist/size.js +34 -0
- package/dist/status-line.js +1 -0
- package/dist/step-board.js +6 -4
- package/dist/sweep.d.ts +45 -18
- package/dist/sweep.js +151 -127
- package/dist/types.d.ts +89 -10
- package/dist/types.js +50 -6
- package/dist/util.d.ts +2 -0
- package/dist/util.js +25 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/dist/worktrees.js +87 -11
- 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
|
|
12
|
-
/** Why
|
|
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
|
|
21
|
-
* a failed listing answered nothing
|
|
22
|
-
*
|
|
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,
|
|
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
|
-
* `
|
|
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(
|
|
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
|
|
13
|
-
* a failed listing answered nothing
|
|
14
|
-
*
|
|
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
|
-
* `
|
|
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(
|
|
61
|
+
export function lookupPrs(at, provider, branch) {
|
|
55
62
|
const byHead = new Map();
|
|
56
|
-
const status =
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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<
|
|
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 =
|
|
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
|
-
|
|
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),
|
package/dist/reference.d.ts
CHANGED
|
@@ -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
|
|
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
|
@@ -11,32 +11,49 @@ const TARGETS = `Targets
|
|
|
11
11
|
directory (https://, ssh://, file://, or user@host:path)
|
|
12
12
|
No target sweeps the directory you are in, read the same way; in a subdirectory
|
|
13
13
|
the checkout around it tracks, where the search finds no checkout, that checkout.`;
|
|
14
|
-
const SWEEP = `
|
|
15
|
-
--
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
const SWEEP = `What to look at (status, plan and clean)
|
|
15
|
+
--local Worktrees and local branches. The default when no scope
|
|
16
|
+
flag is given. No network, unless --fetch.
|
|
17
|
+
--remote Branches on the default remote: origin, else the remote the
|
|
18
|
+
default branch tracks, else the only remote. Fetches it
|
|
19
|
+
first and looks up pull requests.
|
|
20
|
+
--remote=<name> Branches on this remote; --remote='*' is every remote.
|
|
21
|
+
Repeatable, and adds to a bare --remote. Each is fetched,
|
|
22
|
+
and its branches judged against its own default branch.
|
|
23
|
+
--all --local and --remote. With other remotes, write them out:
|
|
24
|
+
--local --remote=upstream.
|
|
25
|
+
--worktrees Only worktrees, of the local rows.
|
|
26
|
+
--branches Only local branches, of the local rows.
|
|
27
|
+
Scope flags add up: --worktrees --remote is worktrees and the default remote's
|
|
28
|
+
branches.
|
|
29
|
+
|
|
30
|
+
How sure
|
|
31
|
+
--fetch Fetch the default remote before judging local rows.
|
|
32
|
+
--offline No network: no fetch; judge against the remote-tracking
|
|
33
|
+
refs already on disk. Tips can be stale; clean asks the
|
|
34
|
+
remote before deleting on it. Pull requests are still
|
|
35
|
+
looked up; add --provider none for no network at all.
|
|
36
|
+
--against <remote> Judge every row against this remote's default branch, as
|
|
37
|
+
a fork against its parent. Without it, a remote's branches
|
|
38
|
+
are judged against its own default branch, and local rows
|
|
39
|
+
against the default remote's.
|
|
40
|
+
--provider <name> With remote rows: where pull requests come from. auto (by
|
|
41
|
+
each remote's host), github, gitlab, or none to judge on
|
|
42
|
+
git evidence alone.
|
|
27
43
|
--branch <name|HEAD> Only the rows of one branch: its worktree, its local branch,
|
|
28
|
-
and its remote
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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.
|
|
44
|
+
and its remote branches. HEAD is the branch checked out at
|
|
45
|
+
the target. Never a default branch.
|
|
46
|
+
|
|
47
|
+
What is shown
|
|
35
48
|
--no-progress No progress line on stderr.`;
|
|
36
|
-
const
|
|
49
|
+
const STATUS = `repo-cleaner status [target...]
|
|
37
50
|
Deletes nothing. Lists each row with its verdict, why, the risks it carries,
|
|
38
51
|
and the command that would delete it.
|
|
39
|
-
--
|
|
52
|
+
--sizes Read each worktree's size on disk (du), list rows largest
|
|
53
|
+
first within each verdict, and total the bytes the delete
|
|
54
|
+
and review rows would free. Slower: it reads every file
|
|
55
|
+
under every worktree. status only; plan and clean refuse it.
|
|
56
|
+
--all-rows Also show keep rows. By default only delete, review and
|
|
40
57
|
blocked rows are listed. Only with --format text.
|
|
41
58
|
--format text The report. The default.
|
|
42
59
|
--format summary Counts per repository: total, merged, delete, prune,
|
|
@@ -49,22 +66,33 @@ const PLAN = `repo-cleaner plan [target...]
|
|
|
49
66
|
-o, --out <file> Where the plan goes; - (the default) is stdout.`;
|
|
50
67
|
const CLEAN = `repo-cleaner clean [target...]
|
|
51
68
|
Sweeps (or reads --plan), checks every row again, shows the steps, asks, then
|
|
52
|
-
deletes, compare-and-swap, verifying each step
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
deletes, compare-and-swap, verifying each step. A failed step skips only the
|
|
70
|
+
steps that depend on it. Every row judged delete runs, and each row picked.
|
|
71
|
+
Ends with what it deleted and the disk space the removed worktrees freed, each
|
|
72
|
+
measured with du just before its removal (freed: 4.2 GB (2 worktrees)); a size
|
|
73
|
+
du could not read makes it "at least". A dry run measures nothing.
|
|
74
|
+
--pick <row> Also run this row: a review row, or a kept row with an
|
|
75
|
+
action (an open pull request), never runs otherwise. A
|
|
76
|
+
picked row still needs --allow for its risks. A blocked
|
|
77
|
+
row is skipped. Repeatable.
|
|
78
|
+
--spare <row|glob> Leave this row, or every row the glob matches, alone. A
|
|
79
|
+
glob matches row names, and a remote branch's name
|
|
80
|
+
without its remote; * stays within a /, ** does not. A
|
|
81
|
+
remote branch spared by name is still checked: if its tip
|
|
82
|
+
moved or it is gone since the plan, the run stops before
|
|
83
|
+
deleting anything. Sparing a worktree also spares its
|
|
84
|
+
branch. Repeatable.
|
|
65
85
|
--allow <risk> Accept this risk for every row that carries it.
|
|
66
86
|
--allow <risk>=<row> Accept it for that one row only.
|
|
67
|
-
--
|
|
87
|
+
-i, --interactive Choose the rows from a checklist: delete rows ticked,
|
|
88
|
+
review rows not, keep and blocked rows shown but not
|
|
89
|
+
selectable. A ticked row's risks are asked for by name.
|
|
90
|
+
Needs a terminal.
|
|
91
|
+
--archive Push unlanded work to an archive branch on the default
|
|
92
|
+
remote before deleting; then --allow discard-archived
|
|
93
|
+
stands for abandon-unmerged and discard-changes.
|
|
94
|
+
--archive-exclude <glob> With --archive, leave these files out of a snapshot.
|
|
95
|
+
--plan <file|-> Clean a saved plan instead of looking now (- reads stdin).
|
|
68
96
|
Rows whose evidence changed since the plan are dropped.
|
|
69
97
|
-y, --yes Do not ask. Without it, and with no terminal to ask on,
|
|
70
98
|
clean refuses.
|
|
@@ -102,6 +130,10 @@ Risks (approve each by name with --allow)
|
|
|
102
130
|
(or its submodules') commits and stashes that no remote has.
|
|
103
131
|
discard-changes Uncommitted or untracked files in the worktree or any of its
|
|
104
132
|
submodules.
|
|
133
|
+
discard-archived With --archive, stands for abandon-unmerged and discard-changes on
|
|
134
|
+
a row whose work the archive holds. Files the snapshot leaves out
|
|
135
|
+
(secret-shaped, --archive-exclude, over 10 MiB) keep discard-changes;
|
|
136
|
+
a worktree's submodule work keeps both risks.
|
|
105
137
|
confirm-open-pr The branch has an open pull request, or open pull requests could
|
|
106
138
|
not be checked (the CLI is missing or signed out, or the listing
|
|
107
139
|
failed); deleting the remote branch closes it.
|
|
@@ -112,41 +144,52 @@ const CONFLICTS = `Refused before anything is deleted (exit 2)
|
|
|
112
144
|
would have no effect. Most are refused before anything is swept; a row named
|
|
113
145
|
two ways (a bare name and its id), and an --allow for a row, are checked
|
|
114
146
|
against the plan, after the sweep.
|
|
147
|
+
no phase named: the bare command explains the phases
|
|
148
|
+
a target that is no directory but a remote's name: write --remote=<name>
|
|
149
|
+
--all with --remote=<name>
|
|
115
150
|
the same row in --pick and --spare
|
|
116
|
-
--allow <risk>=<row> for a spared row
|
|
117
|
-
|
|
151
|
+
--allow <risk>=<row> for a spared row
|
|
152
|
+
-i with --pick, or with --plan -
|
|
153
|
+
a picked or spared row of a kind the scope leaves out
|
|
118
154
|
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
|
|
120
|
-
--plan with targets or sweep options: the plan already fixed them
|
|
155
|
+
--branch with more than one target, or with a remote URL, or a default branch
|
|
156
|
+
--plan with targets, scope flags or sweep options: the plan already fixed them
|
|
121
157
|
--plan - without --yes or --dry-run: stdin carries the plan, so nothing can ask
|
|
122
158
|
--yes with --dry-run
|
|
123
159
|
--receipt with --dry-run
|
|
124
|
-
--
|
|
125
|
-
--
|
|
126
|
-
a remote URL target with --
|
|
127
|
-
|
|
128
|
-
--all with any --format but text
|
|
160
|
+
--fetch with --offline; --fetch with remote rows only
|
|
161
|
+
--offline or --provider without remote rows
|
|
162
|
+
a remote URL target with --worktrees or --branches, with --offline, or mixed
|
|
163
|
+
with checkout targets
|
|
164
|
+
--all-rows with any --format but text
|
|
165
|
+
--sizes with plan or clean: it is a status flag
|
|
129
166
|
|
|
130
167
|
Refused after the sweep, before deleting (exit 1)
|
|
131
168
|
a picked, spared or allowed row the plan does not have
|
|
132
169
|
a row name that matches rows in more than one repository
|
|
133
170
|
a spared remote branch that moved since the plan, or that the re-check no longer finds
|
|
134
171
|
|
|
172
|
+
A repository that cannot be read is an error row, and the rest are swept
|
|
173
|
+
a remote it does not have, or several remotes and none of them the default
|
|
174
|
+
--against a remote it does not have
|
|
175
|
+
--provider github or gitlab over remotes on different kinds of host
|
|
176
|
+
|
|
135
177
|
Allowed, because nothing contradicts
|
|
136
178
|
the same row picked twice: it runs once
|
|
137
179
|
--allow <risk> with --allow <risk>=<row>: the broader one covers it
|
|
138
180
|
--allow for a risk no row that runs carries: the preview lists it as unused
|
|
139
181
|
picking a blocked or keep row: it is skipped and shown with the reason
|
|
140
|
-
|
|
182
|
+
a --spare glob that matches nothing`;
|
|
141
183
|
const EXIT = `Exit codes
|
|
142
|
-
0
|
|
184
|
+
0 looked or saved; or clean ran, was declined, or had nothing to do
|
|
143
185
|
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
|
|
186
|
+
2 cannot run as typed: no phase named, an unknown flag, a malformed row, a
|
|
187
|
+
refused combination
|
|
145
188
|
10 no target named a repository
|
|
146
|
-
11 clean
|
|
189
|
+
11 clean had a failed step; the receipt says which, and which steps it skipped`;
|
|
147
190
|
/** The extended help for each command: its own options, then the shared vocabulary. */
|
|
148
191
|
export const REFERENCE = {
|
|
149
|
-
|
|
192
|
+
status: [TARGETS, SWEEP, STATUS, WORDS, CONFLICTS, EXIT].join('\n\n'),
|
|
150
193
|
plan: [TARGETS, SWEEP, PLAN, WORDS, EXIT].join('\n\n'),
|
|
151
194
|
clean: [TARGETS, SWEEP, CLEAN, WORDS, CONFLICTS, EXIT].join('\n\n'),
|
|
152
195
|
cache: CACHE,
|
package/dist/remote-mirror.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/dist/remote-mirror.js
CHANGED
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* date.
|
|
14
14
|
*/
|
|
15
15
|
import { createHash } from 'node:crypto';
|
|
16
|
-
import { existsSync,
|
|
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
|
-
|
|
75
|
+
succeeded: number;
|
|
76
76
|
failed: number;
|
|
77
|
-
/**
|
|
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[];
|