@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/util.js
CHANGED
|
@@ -34,3 +34,28 @@ function rawErrorText(err) {
|
|
|
34
34
|
const oneLine = (text) => text.replace(/\s*\n\s*/g, ' ').trim();
|
|
35
35
|
/** `1 commit`, `3 commits`. */
|
|
36
36
|
export const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
37
|
+
/** A glob as a regular expression: `*` stays inside a `/`-separated segment, `**` does not, `?` is one character. */
|
|
38
|
+
export function globRegExp(glob) {
|
|
39
|
+
let out = '';
|
|
40
|
+
for (let i = 0; i < glob.length; i++) {
|
|
41
|
+
const c = glob[i];
|
|
42
|
+
if (c === '*') {
|
|
43
|
+
if (glob[i + 1] === '*') {
|
|
44
|
+
i += 1;
|
|
45
|
+
if (glob[i + 1] === '/') {
|
|
46
|
+
i += 1;
|
|
47
|
+
out += '(?:.*/)?';
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
out += '.*';
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
out += '[^/]*';
|
|
54
|
+
}
|
|
55
|
+
else if (c === '?')
|
|
56
|
+
out += '[^/]';
|
|
57
|
+
else
|
|
58
|
+
out += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
59
|
+
}
|
|
60
|
+
return new RegExp(`^${out}$`);
|
|
61
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** This package's version, from its package.json when it was built. */
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.22.0";
|
package/dist/worktrees.js
CHANGED
|
@@ -13,7 +13,7 @@ import { gapSentence, mergedFact, recordPr } from "./branches.js";
|
|
|
13
13
|
import { confirmationNote, judgeLanding, landingConfirmed, recordLanding, unmatchedSentence, } from "./landing.js";
|
|
14
14
|
import { busyHolders, isIdleHolder, parseLockOwner } from "./processes.js";
|
|
15
15
|
import { inspectSubmodules, readIndexHazards, submoduleFacts, unpushedPhrase, unreadablePhrase, worktreeGitDirs, } from "./submodules.js";
|
|
16
|
-
import {
|
|
16
|
+
import { landedFor, refOf, makeRow, risksFor, } from "./types.js";
|
|
17
17
|
import { isDir } from "./util.js";
|
|
18
18
|
/** The command line, not run, that removes the worktree at `path`. */
|
|
19
19
|
export function worktreeRemoveCommand(root, path, opts = {}) {
|
|
@@ -216,6 +216,8 @@ export function gatherWorktrees(repo, prs, cwd, git, only, probe, tick) {
|
|
|
216
216
|
}
|
|
217
217
|
function classifyWorktree(opts) {
|
|
218
218
|
const { path, branch, head, isBare, isDetached, isPrimary, repo, prs, cwd, git } = opts;
|
|
219
|
+
const against = landedFor(repo);
|
|
220
|
+
const landedOn = refOf(against);
|
|
219
221
|
const evidence = {
|
|
220
222
|
path,
|
|
221
223
|
branch: branch || null,
|
|
@@ -271,7 +273,7 @@ function classifyWorktree(opts) {
|
|
|
271
273
|
compareAgainst = upstream.value;
|
|
272
274
|
}
|
|
273
275
|
if (!compareAgainst) {
|
|
274
|
-
compareAgainst =
|
|
276
|
+
compareAgainst = landedOn;
|
|
275
277
|
}
|
|
276
278
|
// `try`: `compareAgainst` is a guess — the fallback `origin/main` need not
|
|
277
279
|
// exist locally, and an unresolvable range renders as zero unpushed commits.
|
|
@@ -285,7 +287,7 @@ function classifyWorktree(opts) {
|
|
|
285
287
|
const branchExists = !!branch && git.at(repo.root).resolveRef(branch) !== null;
|
|
286
288
|
evidence.branchExists = branchExists;
|
|
287
289
|
const pr = branch ? prs.get(branch) : undefined;
|
|
288
|
-
const { landed, gap } = recordPr(evidence, pr, head ?? '',
|
|
290
|
+
const { landed, gap } = recordPr(evidence, pr, head ?? '', against);
|
|
289
291
|
if (unpushed.length > 0)
|
|
290
292
|
evidence.uniqueCommits = unpushed.length;
|
|
291
293
|
// A merged PR at HEAD lands every commit, even ones the fallback
|
|
@@ -293,17 +295,20 @@ function classifyWorktree(opts) {
|
|
|
293
295
|
// A rebase merge, cherry-pick or squash merge leaves HEAD off the default
|
|
294
296
|
// branch; the patches say whether the work is there anyway. Judged from HEAD,
|
|
295
297
|
// so a dirty tree is still caught by the dirty-file check below.
|
|
296
|
-
const patch = landed || !onDisk || head === null
|
|
298
|
+
const patch = landed || !onDisk || head === null
|
|
299
|
+
? null
|
|
300
|
+
: judgeLanding({ root: repo.root, ref: landedOn }, head, pr, gap, git);
|
|
297
301
|
if (patch !== null)
|
|
298
302
|
recordLanding(evidence, patch);
|
|
299
303
|
const patchLanded = patch !== null && patch.check !== null;
|
|
300
|
-
|
|
304
|
+
let unlanded = unpushed.length > 0 && !landed && !landingConfirmed(patch);
|
|
301
305
|
if (onDisk && head !== null) {
|
|
306
|
+
evidence.landedAgainst = landedOn;
|
|
302
307
|
// `soft`: a missing default ref reads as not merged.
|
|
303
308
|
evidence.merged = mergedFact({
|
|
304
309
|
landed,
|
|
305
310
|
patchLanded,
|
|
306
|
-
ancestor: git.at(repo.root).soft.isAncestor(head,
|
|
311
|
+
ancestor: git.at(repo.root).soft.isAncestor(head, landedOn),
|
|
307
312
|
});
|
|
308
313
|
}
|
|
309
314
|
const dirty = dirtyFiles.length > 0 || submoduleDirty > 0;
|
|
@@ -313,6 +318,28 @@ function classifyWorktree(opts) {
|
|
|
313
318
|
// own unpushed commits covers them.
|
|
314
319
|
const submoduleWork = submodules.unpushed.length > 0;
|
|
315
320
|
const submoduleWorkText = submoduleWork ? unpushedPhrase(submodules.unpushed) : '';
|
|
321
|
+
// Work that a remote branch holds is not lost with the worktree. Only a
|
|
322
|
+
// clean worktree on a used branch: a dirty one has files no remote holds;
|
|
323
|
+
// a fresh branch is left alone (see `branchUse`).
|
|
324
|
+
let remoteNote = null;
|
|
325
|
+
const settled = landed || patchLanded || evidence.merged === true;
|
|
326
|
+
if (onDisk && !settled && !dirty && !submoduleWork && branch && head !== null && branchExists) {
|
|
327
|
+
const holders = remoteBranchesHolding(repo, git, head);
|
|
328
|
+
if (holders.length > 0) {
|
|
329
|
+
const used = branchUse(git.at(repo.root), branch, repo.mainBranch);
|
|
330
|
+
evidence.branchUsed = used;
|
|
331
|
+
if (used !== null) {
|
|
332
|
+
const recoverable = holders.filter((h) => repo.fetchedRemotes.includes(remoteOf(h, repo.allRemotes) ?? ''));
|
|
333
|
+
if (recoverable.length > 0) {
|
|
334
|
+
evidence.recoverableFrom = recoverable;
|
|
335
|
+
unlanded = false;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
remoteNote = `HEAD is on ${holders.join(', ')}, but this sweep did not fetch, so those remote-tracking refs may be stale; \`--fetch\` would check them.`;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
316
343
|
const risks = risksFor({
|
|
317
344
|
'abandon-unmerged': unlanded || submoduleWork,
|
|
318
345
|
'discard-changes': dirty,
|
|
@@ -379,9 +406,10 @@ function classifyWorktree(opts) {
|
|
|
379
406
|
: []),
|
|
380
407
|
...(patchLanded && unlanded
|
|
381
408
|
? [
|
|
382
|
-
`Its commits are patch-equivalent to commits on ${
|
|
409
|
+
`Its commits are patch-equivalent to commits on ${landedOn} (${patch.check}), but ${confirmationNote(patch)}.`,
|
|
383
410
|
]
|
|
384
411
|
: []),
|
|
412
|
+
...(remoteNote !== null ? [remoteNote] : []),
|
|
385
413
|
'Decide whether to preserve, push, or discard.',
|
|
386
414
|
],
|
|
387
415
|
});
|
|
@@ -390,7 +418,7 @@ function classifyWorktree(opts) {
|
|
|
390
418
|
if (pr && landed)
|
|
391
419
|
return deletes(`clean; PR #${pr.number} merged${forced}`);
|
|
392
420
|
if (patchLanded) {
|
|
393
|
-
return deletes(`clean; patch-equivalent to commits on ${
|
|
421
|
+
return deletes(`clean; patch-equivalent to commits on ${landedOn} (${patch.check}); ${confirmationNote(patch)}${forced}`);
|
|
394
422
|
}
|
|
395
423
|
if (branch && !branchExists) {
|
|
396
424
|
return deletes(`branch \`${branch}\` no longer exists${forced}`);
|
|
@@ -410,18 +438,23 @@ function classifyWorktree(opts) {
|
|
|
410
438
|
const used = branchUse(git.at(repo.root), branch, repo.mainBranch);
|
|
411
439
|
evidence.branchUsed = used;
|
|
412
440
|
if (used !== null) {
|
|
413
|
-
return deletes(`clean; merged into ${
|
|
441
|
+
return deletes(`clean; merged into ${landedOn}, and ${USE_REASON[used]}${forced}`);
|
|
414
442
|
}
|
|
415
443
|
}
|
|
444
|
+
if (evidence.recoverableFrom !== undefined) {
|
|
445
|
+
return deletes(`clean; HEAD is on ${evidence.recoverableFrom.join(', ')}, and the branch was worked on (${USE_REASON[evidence.branchUsed]})${forced}`);
|
|
446
|
+
}
|
|
416
447
|
const notes = [`Worktree \`${path}\` is clean.`];
|
|
417
448
|
if (branch)
|
|
418
449
|
notes.push(`Branch: \`${branch}\`.`);
|
|
419
450
|
notes.push(pr ? `PR #${pr.number} is ${pr.state}.` : 'No associated PR.');
|
|
420
451
|
if (pr && gap)
|
|
421
|
-
notes.push(gapSentence(pr, gap,
|
|
422
|
-
const unmatched = patch === null ? null : unmatchedSentence(patch,
|
|
452
|
+
notes.push(gapSentence(pr, gap, against));
|
|
453
|
+
const unmatched = patch === null ? null : unmatchedSentence(patch, landedOn);
|
|
423
454
|
if (unmatched !== null)
|
|
424
455
|
notes.push(unmatched);
|
|
456
|
+
if (remoteNote !== null)
|
|
457
|
+
notes.push(remoteNote);
|
|
425
458
|
return row({
|
|
426
459
|
verdict: 'review',
|
|
427
460
|
action: 'remove',
|
|
@@ -431,6 +464,49 @@ function classifyWorktree(opts) {
|
|
|
431
464
|
risks,
|
|
432
465
|
});
|
|
433
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* The remote-tracking branches whose history holds `head`, as
|
|
469
|
+
* `<remote>/<name>`, on the default remote and every remote the sweep judges.
|
|
470
|
+
* Each remote's default branch is left out: ancestry of it has its own rule.
|
|
471
|
+
* Empty when there is no remote or the lookup fails.
|
|
472
|
+
*/
|
|
473
|
+
function remoteBranchesHolding(repo, git, head) {
|
|
474
|
+
const defaults = new Map(repo.remotes.map((r) => [r.name, r.defaultBranch]));
|
|
475
|
+
if (repo.remote !== null)
|
|
476
|
+
defaults.set(repo.remote, repo.mainBranch);
|
|
477
|
+
if (defaults.size === 0)
|
|
478
|
+
return [];
|
|
479
|
+
// One walk of history for every remote, not one per remote.
|
|
480
|
+
const prefixes = [...defaults.keys()].map((r) => `refs/remotes/${r}/`);
|
|
481
|
+
const rows = git.at(repo.root).try.forEachRef(prefixes, { format: '%(refname)', contains: head });
|
|
482
|
+
if (!rows.ok)
|
|
483
|
+
return [];
|
|
484
|
+
const out = [];
|
|
485
|
+
for (const ref of rows.value) {
|
|
486
|
+
const name = ref.slice('refs/remotes/'.length);
|
|
487
|
+
const remote = remoteOf(name, repo.allRemotes);
|
|
488
|
+
const defaultBranch = remote === null ? undefined : defaults.get(remote);
|
|
489
|
+
if (defaultBranch === undefined)
|
|
490
|
+
continue;
|
|
491
|
+
if (name === `${remote}/HEAD` || name === `${remote}/${defaultBranch}`)
|
|
492
|
+
continue;
|
|
493
|
+
if (!out.includes(name))
|
|
494
|
+
out.push(name);
|
|
495
|
+
}
|
|
496
|
+
return out.sort();
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* The remote `name` (`origin/feat/x`) is a branch of: the longest remote name
|
|
500
|
+
* it starts with, since git allows `/` in one (`origin/mirror`). Null for none.
|
|
501
|
+
*/
|
|
502
|
+
function remoteOf(name, remotes) {
|
|
503
|
+
let found = null;
|
|
504
|
+
for (const r of remotes) {
|
|
505
|
+
if (name.startsWith(`${r}/`) && (found === null || r.length > found.length))
|
|
506
|
+
found = r;
|
|
507
|
+
}
|
|
508
|
+
return found;
|
|
509
|
+
}
|
|
434
510
|
const USE_REASON = {
|
|
435
511
|
commits: 'the branch has commits made on it',
|
|
436
512
|
upstream: 'the branch was pushed to its own upstream',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/repo-cleaner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "What has been merged into the default branch, and what can go away. Inventories local branches, worktrees and remote branches across one repository or many, classifying each with the evidence behind the verdict and the command that would act on it. Plans and applies approved deletes, compare-and-swap.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -49,11 +49,12 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"zod": "^4.6.6",
|
|
52
|
-
"@osdlc/cli-tool": "^0.
|
|
53
|
-
"@osdlc/command-seam": "^0.15.
|
|
52
|
+
"@osdlc/cli-tool": "^0.21.0",
|
|
53
|
+
"@osdlc/command-seam": "^0.15.1",
|
|
54
|
+
"@osdlc/file-lock": "^0.4.0",
|
|
54
55
|
"@osdlc/path-guard": "^0.3.1",
|
|
55
|
-
"@osdlc/typed-
|
|
56
|
-
"@osdlc/typed-
|
|
56
|
+
"@osdlc/typed-gh": "^0.19.0",
|
|
57
|
+
"@osdlc/typed-git": "^0.19.0",
|
|
57
58
|
"@osdlc/ux": "^0.1.1"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|