@osdlc/repo-cleaner 0.20.4 → 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 +72 -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/branches.d.ts
CHANGED
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
* leaves the branch for a person to look at.
|
|
11
11
|
*/
|
|
12
12
|
import { type Git } from '@osdlc/typed-git';
|
|
13
|
-
import { type BranchRow, type LandingEvidence, type PRInfo, type PrEvidenceGap, type RemoteRow, type RepoInfo } from './types.ts';
|
|
13
|
+
import { type LandedAgainst, type BranchRow, type LandingEvidence, type PRInfo, type PrEvidenceGap, type RemoteInfo, type RemoteRow, type RepoInfo } from './types.ts';
|
|
14
14
|
/**
|
|
15
15
|
* `evidence.pr`, plus `proof` for a merged PR: `exact-head` when it proves
|
|
16
16
|
* `tip` landed, otherwise the gap. Returns whether it counts as landing proof.
|
|
17
17
|
*/
|
|
18
|
-
export declare function recordPr(evidence: LandingEvidence, pr: PRInfo | undefined, tip: string,
|
|
18
|
+
export declare function recordPr(evidence: LandingEvidence, pr: PRInfo | undefined, tip: string, against: LandedAgainst): {
|
|
19
19
|
landed: boolean;
|
|
20
20
|
gap: PrEvidenceGap | null;
|
|
21
21
|
};
|
|
22
22
|
/** One sentence on why a merged PR did not count, for a row's notes. */
|
|
23
|
-
export declare function gapSentence(pr: PRInfo, gap: PrEvidenceGap,
|
|
23
|
+
export declare function gapSentence(pr: PRInfo, gap: PrEvidenceGap, against: LandedAgainst): string;
|
|
24
24
|
/**
|
|
25
25
|
* `evidence.merged`: the work is on the default branch, by an exact-head
|
|
26
26
|
* merged PR, by ancestry or by a patch match. Every kind records it this way,
|
|
@@ -68,7 +68,7 @@ export interface RemoteBranches {
|
|
|
68
68
|
* re-check when nothing was fetched) the refs on disk are what the re-check
|
|
69
69
|
* is there to replace, so a failed listing throws instead.
|
|
70
70
|
*/
|
|
71
|
-
export declare function gatherRemoteBranches(repo: RepoInfo, prs: Map<string, PRInfo>, localBranchNames: ReadonlySet<string>, git: Git, opts: {
|
|
71
|
+
export declare function gatherRemoteBranches(repo: RepoInfo, remoteInfo: RemoteInfo, prs: Map<string, PRInfo>, localBranchNames: ReadonlySet<string>, git: Git, opts: {
|
|
72
72
|
live: boolean;
|
|
73
73
|
strict?: boolean | undefined;
|
|
74
74
|
only?: string | undefined;
|
package/dist/branches.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { shellJoin } from '@osdlc/command-seam';
|
|
13
13
|
import { forceWithLeaseArg } from '@osdlc/typed-git';
|
|
14
14
|
import { confirmationNote, judgeLanding, landingConfirmed, recordLanding, unmatchedSentence, } from "./landing.js";
|
|
15
|
-
import {
|
|
15
|
+
import { landedFor, refOf, makeRow, risksFor, } from "./types.js";
|
|
16
16
|
import { prsUnchecked } from "./prs.js";
|
|
17
17
|
import { errorText } from "./util.js";
|
|
18
18
|
/**
|
|
@@ -21,12 +21,12 @@ import { errorText } from "./util.js";
|
|
|
21
21
|
*/
|
|
22
22
|
const LOCAL_FORMAT = '%(refname:short)%09%(upstream:short)%09%(upstream:track)%09%(committerdate:iso8601-strict)%09%(objectname)';
|
|
23
23
|
/**
|
|
24
|
-
* True when merged `pr` proves `tip` landed: it targeted the
|
|
25
|
-
* and its head commit is `tip`. Fork PRs never reach here; the
|
|
26
|
-
* them. A PR with no reported head counts as `head-moved`.
|
|
24
|
+
* True when merged `pr` proves `tip` landed: it targeted the branch the row is
|
|
25
|
+
* judged against and its head commit is `tip`. Fork PRs never reach here; the
|
|
26
|
+
* provider drops them. A PR with no reported head counts as `head-moved`.
|
|
27
27
|
*/
|
|
28
|
-
function prCapturesTip(pr, tip,
|
|
29
|
-
if (pr.baseRef !==
|
|
28
|
+
function prCapturesTip(pr, tip, against) {
|
|
29
|
+
if (pr.baseRef !== against.branch)
|
|
30
30
|
return 'other-base';
|
|
31
31
|
if (pr.headOid === null || pr.headOid !== tip)
|
|
32
32
|
return 'head-moved';
|
|
@@ -36,7 +36,7 @@ function prCapturesTip(pr, tip, repo) {
|
|
|
36
36
|
* `evidence.pr`, plus `proof` for a merged PR: `exact-head` when it proves
|
|
37
37
|
* `tip` landed, otherwise the gap. Returns whether it counts as landing proof.
|
|
38
38
|
*/
|
|
39
|
-
export function recordPr(evidence, pr, tip,
|
|
39
|
+
export function recordPr(evidence, pr, tip, against) {
|
|
40
40
|
if (pr === undefined)
|
|
41
41
|
return { landed: false, gap: null };
|
|
42
42
|
const { headRef: _, ...rest } = pr;
|
|
@@ -44,13 +44,12 @@ export function recordPr(evidence, pr, tip, repo) {
|
|
|
44
44
|
evidence.pr = out;
|
|
45
45
|
if (pr.state !== 'MERGED')
|
|
46
46
|
return { landed: false, gap: null };
|
|
47
|
-
const verdict = prCapturesTip(pr, tip,
|
|
47
|
+
const verdict = prCapturesTip(pr, tip, against);
|
|
48
48
|
out.proof = verdict === true ? 'exact-head' : verdict;
|
|
49
49
|
return verdict === true ? { landed: true, gap: null } : { landed: false, gap: verdict };
|
|
50
50
|
}
|
|
51
51
|
/** Why a branch has no PR, naming where the sweep looked, or why it could not. */
|
|
52
|
-
function noPrSentence(
|
|
53
|
-
const provider = repo.provider;
|
|
52
|
+
function noPrSentence(provider) {
|
|
54
53
|
if (provider === null)
|
|
55
54
|
return 'No PR lookup (no provider).';
|
|
56
55
|
// The provider's own error is in the repository's note, not on every row.
|
|
@@ -60,9 +59,9 @@ function noPrSentence(repo) {
|
|
|
60
59
|
return `No ${provider.noun} found via \`${provider.listing}\`.`;
|
|
61
60
|
}
|
|
62
61
|
/** One sentence on why a merged PR did not count, for a row's notes. */
|
|
63
|
-
export function gapSentence(pr, gap,
|
|
62
|
+
export function gapSentence(pr, gap, against) {
|
|
64
63
|
return gap === 'other-base'
|
|
65
|
-
? `PR #${pr.number} merged into \`${pr.baseRef}\`, not \`${
|
|
64
|
+
? `PR #${pr.number} merged into \`${pr.baseRef}\`, not \`${against.branch}\`, so it is not landing proof (other-base).`
|
|
66
65
|
: `PR #${pr.number} merged at head ${pr.headOid ?? '(unknown)'}, which is not this tip, so it is not landing proof (head-moved).`;
|
|
67
66
|
}
|
|
68
67
|
/**
|
|
@@ -156,6 +155,9 @@ function classifyLocalBranch(opts) {
|
|
|
156
155
|
const pinned = (why) => row({ verdict: 'keep', action: null, why });
|
|
157
156
|
if (name === repo.mainBranch)
|
|
158
157
|
return pinned('default branch');
|
|
158
|
+
const against = landedFor(repo);
|
|
159
|
+
const compareRef = refOf(against);
|
|
160
|
+
const onto = { root: repo.root, ref: compareRef };
|
|
159
161
|
const held = name === repo.currentBranch
|
|
160
162
|
? 'current HEAD'
|
|
161
163
|
: worktreeBranches.has(name)
|
|
@@ -166,27 +168,27 @@ function classifyLocalBranch(opts) {
|
|
|
166
168
|
// an exact-head merged PR, without the patch checks a deletable row gets.
|
|
167
169
|
// `soft`: a missing default ref reads as not merged.
|
|
168
170
|
const pr = prs.get(name);
|
|
169
|
-
const { landed } = recordPr(evidence, pr, sha,
|
|
171
|
+
const { landed } = recordPr(evidence, pr, sha, against);
|
|
172
|
+
evidence.landedAgainst = compareRef;
|
|
170
173
|
evidence.merged = mergedFact({
|
|
171
174
|
landed,
|
|
172
|
-
ancestor: git.at(repo.root).soft.isAncestor(sha,
|
|
175
|
+
ancestor: git.at(repo.root).soft.isAncestor(sha, compareRef),
|
|
173
176
|
patchLanded: false,
|
|
174
177
|
});
|
|
175
178
|
return pinned(held);
|
|
176
179
|
}
|
|
177
180
|
// Work merged only into an unpushed local default has not landed. A missing
|
|
178
181
|
// remote-tracking ref exits 128: ancestry unknown (null).
|
|
179
|
-
|
|
180
|
-
evidence.compareAgainst = compareRef;
|
|
182
|
+
evidence.landedAgainst = compareRef;
|
|
181
183
|
const ancestry = git.at(repo.root).try.isAncestor(name, compareRef);
|
|
182
184
|
const ancestor = ancestry.ok ? ancestry.value : null;
|
|
183
185
|
evidence.ancestorOfRemoteMain = ancestor;
|
|
184
186
|
const isAncestor = ancestor === true;
|
|
185
187
|
const pr = prs.get(name);
|
|
186
|
-
const { landed, gap } = recordPr(evidence, pr, sha,
|
|
188
|
+
const { landed, gap } = recordPr(evidence, pr, sha, against);
|
|
187
189
|
// Rebase merges, cherry-picks and squash merges leave the tip off the default
|
|
188
190
|
// branch; the patches say whether the work is there anyway.
|
|
189
|
-
const patch = landed || isAncestor ? null : judgeLanding(
|
|
191
|
+
const patch = landed || isAncestor ? null : judgeLanding(onto, sha, pr, gap, git);
|
|
190
192
|
if (patch !== null)
|
|
191
193
|
recordLanding(evidence, patch);
|
|
192
194
|
const patchLanded = patch !== null && patch.check !== null;
|
|
@@ -213,10 +215,10 @@ function classifyLocalBranch(opts) {
|
|
|
213
215
|
: `Branch \`${name}\` is not an ancestor of \`${compareRef}\`.`;
|
|
214
216
|
const notes = [lead];
|
|
215
217
|
notes.push(upstream ? `Tracks \`${upstream}\` (${track || 'in sync'}).` : 'Has no upstream.');
|
|
216
|
-
notes.push(pr ? `Associated PR #${pr.number} is ${pr.state} (${pr.url}).` : noPrSentence(repo));
|
|
218
|
+
notes.push(pr ? `Associated PR #${pr.number} is ${pr.state} (${pr.url}).` : noPrSentence(repo.provider));
|
|
217
219
|
if (pr && gap)
|
|
218
|
-
notes.push(gapSentence(pr, gap,
|
|
219
|
-
const unmatched = patch === null ? null : unmatchedSentence(patch,
|
|
220
|
+
notes.push(gapSentence(pr, gap, against));
|
|
221
|
+
const unmatched = patch === null ? null : unmatchedSentence(patch, compareRef);
|
|
220
222
|
if (unmatched !== null)
|
|
221
223
|
notes.push(unmatched);
|
|
222
224
|
notes.push(`Last commit: ${lastCommit} (${sha}).`);
|
|
@@ -243,10 +245,8 @@ function classifyLocalBranch(opts) {
|
|
|
243
245
|
* re-check when nothing was fetched) the refs on disk are what the re-check
|
|
244
246
|
* is there to replace, so a failed listing throws instead.
|
|
245
247
|
*/
|
|
246
|
-
export function gatherRemoteBranches(repo, prs, localBranchNames, git, opts) {
|
|
247
|
-
const remote =
|
|
248
|
-
if (remote === null)
|
|
249
|
-
return { rows: [], note: null };
|
|
248
|
+
export function gatherRemoteBranches(repo, remoteInfo, prs, localBranchNames, git, opts) {
|
|
249
|
+
const remote = remoteInfo.name;
|
|
250
250
|
const { only, tick } = opts;
|
|
251
251
|
let tips = null;
|
|
252
252
|
let note = null;
|
|
@@ -264,7 +264,7 @@ export function gatherRemoteBranches(repo, prs, localBranchNames, git, opts) {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
if (tips === null) {
|
|
267
|
-
tips = trackingTips(repo
|
|
267
|
+
tips = trackingTips(repo, remote, git, only);
|
|
268
268
|
// A fetched remote has at least its default branch on disk; none at all
|
|
269
269
|
// means it was never fetched, or its refs live somewhere else.
|
|
270
270
|
if (!opts.live && tips.length === 0 && only === undefined) {
|
|
@@ -276,7 +276,15 @@ export function gatherRemoteBranches(repo, prs, localBranchNames, git, opts) {
|
|
|
276
276
|
tick?.(i, tips.length);
|
|
277
277
|
if (only !== undefined && name !== only)
|
|
278
278
|
continue;
|
|
279
|
-
const row = classifyRemoteBranch({
|
|
279
|
+
const row = classifyRemoteBranch({
|
|
280
|
+
name,
|
|
281
|
+
sha,
|
|
282
|
+
repo,
|
|
283
|
+
remote: remoteInfo,
|
|
284
|
+
prs,
|
|
285
|
+
localBranchNames,
|
|
286
|
+
git,
|
|
287
|
+
});
|
|
280
288
|
if (note !== null) {
|
|
281
289
|
row.notes.push(`Tip read from \`refs/remotes/${remote}/${name}\` on disk: \`git ls-remote\` failed.`);
|
|
282
290
|
}
|
|
@@ -289,13 +297,12 @@ export function gatherRemoteBranches(repo, prs, localBranchNames, git, opts) {
|
|
|
289
297
|
* the default `refs/remotes/<remote>/` layout. The symbolic `HEAD` is not a
|
|
290
298
|
* branch.
|
|
291
299
|
*/
|
|
292
|
-
function trackingTips(
|
|
300
|
+
function trackingTips(repo, remote, git, only) {
|
|
293
301
|
const prefix = `refs/remotes/${remote}/`;
|
|
294
|
-
const at = git.at(root);
|
|
302
|
+
const at = git.at(repo.root);
|
|
295
303
|
// Git allows `/` in a remote's name: `origin/mirror`'s refs sit under
|
|
296
304
|
// `refs/remotes/origin/` too, and are not `origin`'s branches.
|
|
297
|
-
const nested =
|
|
298
|
-
.remotes()
|
|
305
|
+
const nested = repo.allRemotes
|
|
299
306
|
.filter((r) => r.startsWith(`${remote}/`))
|
|
300
307
|
.map((r) => `refs/remotes/${r}/`);
|
|
301
308
|
return at.refs(only === undefined ? prefix : `${prefix}${only}`).flatMap(({ sha, ref }) => {
|
|
@@ -307,7 +314,7 @@ function trackingTips(root, remote, git, only) {
|
|
|
307
314
|
}
|
|
308
315
|
function classifyRemoteBranch(opts) {
|
|
309
316
|
const { name: branch, sha, repo, prs, localBranchNames, git } = opts;
|
|
310
|
-
const remote =
|
|
317
|
+
const remote = opts.remote.name;
|
|
311
318
|
const name = `${remote}/${branch}`;
|
|
312
319
|
const evidence = {
|
|
313
320
|
branch,
|
|
@@ -316,19 +323,24 @@ function classifyRemoteBranch(opts) {
|
|
|
316
323
|
hasLocal: localBranchNames.has(branch),
|
|
317
324
|
};
|
|
318
325
|
const row = (r) => makeRow({ kind: 'remote', name, evidence, ...r });
|
|
319
|
-
if (branch ===
|
|
326
|
+
if (branch === opts.remote.defaultBranch) {
|
|
320
327
|
return row({ verdict: 'keep', action: null, why: 'default branch' });
|
|
321
|
-
|
|
328
|
+
}
|
|
329
|
+
const against = landedFor(repo, opts.remote);
|
|
330
|
+
const remoteMain = refOf(against);
|
|
331
|
+
evidence.landedAgainst = remoteMain;
|
|
322
332
|
// `soft`: `sha` may come from `ls-remote`, so the clone may never have
|
|
323
333
|
// fetched it, and `remoteMain` may not exist either. Both exit 128; this row
|
|
324
334
|
// renders "cannot tell" as false.
|
|
325
335
|
const isAncestor = git.at(repo.root).soft.isAncestor(sha, remoteMain);
|
|
326
336
|
evidence.ancestorOfRemoteMain = isAncestor;
|
|
327
337
|
const pr = prs.get(branch);
|
|
328
|
-
const { landed, gap } = recordPr(evidence, pr, sha,
|
|
338
|
+
const { landed, gap } = recordPr(evidence, pr, sha, against);
|
|
329
339
|
// A `sha` from `ls-remote` may not be in this clone; the check then finds
|
|
330
340
|
// nothing and the branch stays unlanded.
|
|
331
|
-
const patch = landed || isAncestor
|
|
341
|
+
const patch = landed || isAncestor
|
|
342
|
+
? null
|
|
343
|
+
: judgeLanding({ root: repo.root, ref: remoteMain }, sha, pr, gap, git);
|
|
332
344
|
if (patch !== null)
|
|
333
345
|
recordLanding(evidence, patch);
|
|
334
346
|
const patchLanded = patch !== null && patch.check !== null;
|
|
@@ -339,15 +351,16 @@ function classifyRemoteBranch(opts) {
|
|
|
339
351
|
const counted = git.at(repo.root).try.aheadBehind(remoteMain, sha);
|
|
340
352
|
evidence.uniqueCommits = counted.ok ? counted.value.ahead : null;
|
|
341
353
|
}
|
|
342
|
-
const status =
|
|
354
|
+
const status = opts.remote.provider;
|
|
343
355
|
// `--provider none` is a choice that this remote has no forge; anything else
|
|
344
|
-
// that left PRs unchecked means one could be open.
|
|
345
|
-
|
|
356
|
+
// that left PRs unchecked means one could be open. A merged or closed PR
|
|
357
|
+
// does not rule out an open one the listing missed, so only an open PR ends the doubt.
|
|
358
|
+
const unchecked = status === null || pr?.state === 'OPEN' ? null : prsUnchecked(status);
|
|
346
359
|
const unknownPr = status === null || unchecked === null
|
|
347
360
|
? null
|
|
348
361
|
: `Whether it has an open ${status.noun} is unknown (${unchecked.why}), so deleting it needs confirm-open-pr.`;
|
|
349
362
|
const risks = branchRisks(unmerged, pr, unknownPr !== null);
|
|
350
|
-
const commands =
|
|
363
|
+
const commands = [remoteDeleteCommand(remote, branch, sha)];
|
|
351
364
|
const deletes = (why) => row({
|
|
352
365
|
verdict: 'delete',
|
|
353
366
|
action: 'delete',
|
|
@@ -367,10 +380,10 @@ function classifyRemoteBranch(opts) {
|
|
|
367
380
|
return row({ verdict: 'keep', action: 'delete', why: `open PR #${pr.number}`, commands, risks });
|
|
368
381
|
}
|
|
369
382
|
const notes = [`Remote branch \`${name}\` is not an ancestor of \`${remoteMain}\`.`];
|
|
370
|
-
notes.push(pr ? `Associated PR #${pr.number} is ${pr.state}.` : (unknownPr ?? noPrSentence(
|
|
383
|
+
notes.push(pr ? `Associated PR #${pr.number} is ${pr.state}.` : (unknownPr ?? noPrSentence(status)));
|
|
371
384
|
if (pr && gap)
|
|
372
|
-
notes.push(gapSentence(pr, gap,
|
|
373
|
-
const unmatched = patch === null ? null : unmatchedSentence(patch,
|
|
385
|
+
notes.push(gapSentence(pr, gap, against));
|
|
386
|
+
const unmatched = patch === null ? null : unmatchedSentence(patch, remoteMain);
|
|
374
387
|
if (unmatched !== null)
|
|
375
388
|
notes.push(unmatched);
|
|
376
389
|
notes.push('Decide whether to push more work, delete, or leave it as long-lived.');
|
package/dist/clean.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cleaning up: `check` a plan against an approval, then `run` what it shows.
|
|
3
3
|
*
|
|
4
|
-
* `check` resolves the approval (the rows picked, the rows
|
|
5
|
-
* allowed), refuses one that contradicts itself, sweeps every plan repository
|
|
4
|
+
* `check` resolves the approval (the rows selected or picked, the rows
|
|
5
|
+
* spared, the risks allowed), refuses one that contradicts itself, sweeps every plan repository
|
|
6
6
|
* again and drops each selected row that is gone, cannot be deleted, moved
|
|
7
7
|
* since the plan, or carries a risk not allowed. It returns the steps a run
|
|
8
8
|
* would take. `run` sweeps once more and takes those steps in a fixed order,
|
|
9
|
-
*
|
|
9
|
+
* skipping only the steps that depend on a failed one (a failed tip check of a
|
|
10
|
+
* spared remote branch stops the run):
|
|
10
11
|
*
|
|
11
12
|
* 1. spared remote branches, each tip checked with `ls-remote`;
|
|
12
|
-
* 2.
|
|
13
|
+
* 2. with `archive`, one archive per repository, pushed to its remote and
|
|
14
|
+
* checked with `ls-remote` before anything is deleted (see `archive.ts`);
|
|
15
|
+
* 3. worktrees, each unlocked first when its lock's owner is dead, and each
|
|
13
16
|
* checked again for live processes just before it is unlocked or removed;
|
|
14
17
|
* one with submodules is removed with `--force` after its files and every
|
|
15
18
|
* submodule are checked again;
|
|
16
|
-
*
|
|
17
|
-
*
|
|
19
|
+
* 4. local branches;
|
|
20
|
+
* 5. remote branches.
|
|
18
21
|
*
|
|
19
22
|
* A worktree whose directory is gone goes by its own record. One left without
|
|
20
23
|
* its `.git` takes the repository-wide prune, last, and only while that prune
|
|
@@ -23,46 +26,13 @@
|
|
|
23
26
|
* Branch deletes are compare-and-swap on the planned sha. Every step is
|
|
24
27
|
* verified, and the receipt is rewritten after each.
|
|
25
28
|
*/
|
|
29
|
+
import { type ArchiveOptions } from './archive.ts';
|
|
30
|
+
import { type Approval, type ResolvedApproval } from './approval.ts';
|
|
26
31
|
import type { Annotate } from './hooks.ts';
|
|
27
32
|
import { type Plan } from './plan.ts';
|
|
28
33
|
import { type Dropped, type Receipt, type Step } from './receipt.ts';
|
|
29
34
|
import { type Runners } from './sweep.ts';
|
|
30
|
-
import { type
|
|
31
|
-
/** A risk allowed for every row (`row` absent), or for one row. */
|
|
32
|
-
export interface Allow {
|
|
33
|
-
risk: Risk;
|
|
34
|
-
/** A row id or bare name, resolved as a pick is. */
|
|
35
|
-
row?: string | undefined;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* What a person approved. Rows are named by id (`branch:feat/x`), or by a
|
|
39
|
-
* bare name or path when only one plan row has it.
|
|
40
|
-
*
|
|
41
|
-
* `pick` work on exactly these rows; a `review` row, or a `keep` row with
|
|
42
|
-
* an action, runs only when picked. Default: every `delete` row.
|
|
43
|
-
* `spare` leave these rows alone; a spared remote branch is still checked,
|
|
44
|
-
* and the run stops if it moved or is gone since the plan.
|
|
45
|
-
* `allow` the risks a row's action may carry.
|
|
46
|
-
*/
|
|
47
|
-
export interface Approval {
|
|
48
|
-
pick?: readonly string[] | undefined;
|
|
49
|
-
spare?: readonly string[] | undefined;
|
|
50
|
-
allow?: readonly (Risk | Allow)[] | undefined;
|
|
51
|
-
}
|
|
52
|
-
/** A row reference resolved to one plan row. */
|
|
53
|
-
export interface Resolved {
|
|
54
|
-
repo: string;
|
|
55
|
-
id: RowId;
|
|
56
|
-
}
|
|
57
|
-
/** An approval with every row resolved to its plan row. */
|
|
58
|
-
export interface ResolvedApproval {
|
|
59
|
-
pick: Resolved[];
|
|
60
|
-
spare: Resolved[];
|
|
61
|
-
allow: {
|
|
62
|
-
risk: Risk;
|
|
63
|
-
row: Resolved | null;
|
|
64
|
-
}[];
|
|
65
|
-
}
|
|
35
|
+
import { type Risk, type RowId, type Sweep, type SweepProgress, type RepoNote } from './types.ts';
|
|
66
36
|
interface Shared extends Runners {
|
|
67
37
|
/** Where the caller stands: the base for relative worktree paths, and a worktree never removed. Defaults to the process's cwd. */
|
|
68
38
|
cwd?: string | undefined;
|
|
@@ -70,6 +40,13 @@ interface Shared extends Runners {
|
|
|
70
40
|
annotate?: Annotate | undefined;
|
|
71
41
|
/** Told what the re-sweep is doing, for a status line. */
|
|
72
42
|
onProgress?: ((progress: SweepProgress) => void) | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Archive unlanded work to the repository's remote before anything is
|
|
45
|
+
* deleted, and let `discard-archived` stand for `abandon-unmerged` and
|
|
46
|
+
* `discard-changes` on a row the archive holds. Pass it to `check`; `run`
|
|
47
|
+
* takes it from the preview unless given again.
|
|
48
|
+
*/
|
|
49
|
+
archive?: ArchiveOptions | undefined;
|
|
73
50
|
}
|
|
74
51
|
export interface CheckOptions extends Shared {
|
|
75
52
|
/**
|
|
@@ -100,6 +77,11 @@ export interface RunOptions extends Shared {
|
|
|
100
77
|
* listing fails only at the run.
|
|
101
78
|
*/
|
|
102
79
|
onNotes?: ((notes: RepoNote[]) => void) | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* How long measuring a worktree before its removal may take, in ms, for the
|
|
82
|
+
* step's `freedBytes`. Defaults to {@link sizeOf}'s cap.
|
|
83
|
+
*/
|
|
84
|
+
sizeTimeoutMs?: number | undefined;
|
|
103
85
|
}
|
|
104
86
|
/** What a run would do, for a person to approve: the steps, and the rows dropped and why. */
|
|
105
87
|
export interface Preview {
|
|
@@ -119,33 +101,9 @@ export interface Preview {
|
|
|
119
101
|
* of that sweep; otherwise each plan repository the re-check swept again.
|
|
120
102
|
*/
|
|
121
103
|
notes: RepoNote[];
|
|
104
|
+
/** The archive option `check` was given. */
|
|
105
|
+
archive?: ArchiveOptions | undefined;
|
|
122
106
|
}
|
|
123
|
-
/** A row reference as typed: a kind and a name, or a bare name (`kind: null`). */
|
|
124
|
-
export interface RowRef {
|
|
125
|
-
kind: Kind | null;
|
|
126
|
-
name: string;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* `kind:name`, or a bare name. A word before a colon that is not a kind is an
|
|
130
|
-
* error (a typo such as `wt:x`), but a path is a bare name whatever colons it
|
|
131
|
-
* holds: a prefix with a path separator in it is never a kind.
|
|
132
|
-
*/
|
|
133
|
-
export declare function parseRowRef(text: string): RowRef;
|
|
134
|
-
/** `<risk>` for every row, or `<risk>=<row>` for one. */
|
|
135
|
-
export declare function parseAllow(text: string): Allow;
|
|
136
|
-
/**
|
|
137
|
-
* What can be refused of `approval` before anything is swept: a malformed
|
|
138
|
-
* row or risk, a row a sweep with `options` could never hold, and a row
|
|
139
|
-
* picked and spared as written. A row named two ways, and an `allow` for a
|
|
140
|
-
* spared or unpicked row, are found when the approval is resolved against
|
|
141
|
-
* the plan.
|
|
142
|
-
*/
|
|
143
|
-
export declare function checkApproval(options: Pick<SweptWith, 'only' | 'branch'>, approval: Approval): void;
|
|
144
|
-
/**
|
|
145
|
-
* `approval` resolved against `plan`, or a {@link RepoCleanerError} for one
|
|
146
|
-
* that contradicts itself or names rows the plan does not have.
|
|
147
|
-
*/
|
|
148
|
-
export declare function resolveApproval(plan: Plan, approval: Approval, cwd: string): ResolvedApproval;
|
|
149
107
|
/**
|
|
150
108
|
* A network URL as `host[:port]/path`, the same for `git@host:o/r.git`,
|
|
151
109
|
* `ssh://git@host/o/r` and `https://host/o/r/`; the whole path is kept, so
|
|
@@ -168,8 +126,10 @@ export declare function check(plan: Plan, approval: Approval, opts?: CheckOption
|
|
|
168
126
|
/**
|
|
169
127
|
* Take the steps `preview` showed: sweeps again, drops a row that moved since
|
|
170
128
|
* the preview, and runs the rest in order, compare-and-swap, verifying each
|
|
171
|
-
* step
|
|
172
|
-
*
|
|
129
|
+
* step. A failed step skips only the steps that depend on it, except a failed
|
|
130
|
+
* spared-tip check, which stops the run. Only what the preview showed runs; a
|
|
131
|
+
* row it dropped stays dropped. Each worktree directory it removes is measured
|
|
132
|
+
* with `du` just before, into that step's `freedBytes`.
|
|
173
133
|
*
|
|
174
134
|
* @throws RepoCleanerError (`spared-changed`) when a spared remote branch moved
|
|
175
135
|
* since the preview, and a plain `Error` when the re-check cannot read a
|