@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.
- package/CHANGELOG.md +92 -0
- package/README.md +562 -167
- 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/candidates.d.ts +42 -0
- package/dist/candidates.js +42 -0
- package/dist/clean.d.ts +66 -70
- package/dist/clean.js +386 -218
- package/dist/cli.d.ts +16 -10
- package/dist/cli.js +273 -102
- package/dist/discover.d.ts +28 -7
- package/dist/discover.js +185 -42
- package/dist/index.d.ts +12 -5
- package/dist/index.js +11 -4
- 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 +99 -51
- 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 +81 -14
- package/dist/resolve.d.ts +12 -1
- package/dist/resolve.js +15 -3
- 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 +50 -18
- package/dist/sweep.js +152 -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/README.md
CHANGED
|
@@ -2,31 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
What has been merged into the default branch, and what can go away.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
repo-cleaner finds the worktrees, local branches and remote branches whose
|
|
6
|
+
work has landed, and deletes them safely. It judges each one `delete`,
|
|
7
7
|
`review`, `keep` or `blocked`, with the evidence behind the verdict, the risks
|
|
8
8
|
deleting it carries, and the literal command that would delete it.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
`repo-cleaner clean` deletes: it checks each row again, shows you what it
|
|
12
|
-
will delete and skip, and asks before it runs.
|
|
10
|
+
It works in three phases, and runs nothing until one is named:
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
branches. Remote branches are shared, often number in the hundreds, and each
|
|
20
|
-
one is compared with the default branch, so they make a sweep much slower. A
|
|
21
|
-
local report ends with a line saying what it left out.
|
|
12
|
+
| Phase | Command | What it does | Deletes? |
|
|
13
|
+
|---|---|---|---|
|
|
14
|
+
| **status** | `repo-cleaner status` | Looks: every row with its verdict, the reason, and the git command that would delete it | Never |
|
|
15
|
+
| **plan** | `repo-cleaner plan -o <file>` | Saves what status found: each row with its fingerprint, and the options it ran with | Never |
|
|
16
|
+
| **clean** | `repo-cleaner clean`, or `clean --plan <file>` | Checks each row again, shows the steps, asks, and deletes what it may | Yes |
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
By default it looks at your own machine only: worktrees and local branches,
|
|
19
|
+
nothing fetched, no pull-request lookup, judged against the `origin/<default>`
|
|
20
|
+
you last fetched (the header says `not fetched`). `--remote` judges a remote's
|
|
21
|
+
branches too: it fetches the remote first and asks GitHub or GitLab about pull
|
|
22
|
+
requests. Remote branches are shared and often number in the hundreds, so
|
|
23
|
+
they make a look much slower.
|
|
27
24
|
|
|
28
25
|
```console
|
|
29
|
-
$ repo-cleaner --
|
|
26
|
+
$ repo-cleaner status --all
|
|
30
27
|
/Users/me/work/api (acme/api, default main, origin)
|
|
31
28
|
branch fix/login-redirect delete PR #412 merged
|
|
32
29
|
git update-ref -d refs/heads/fix/login-redirect 3f9c2e1d8b7a6c5d4e3f2a1b0c9d8e7f6a5b4c3d
|
|
@@ -40,6 +37,10 @@ $ repo-cleaner --remote
|
|
|
40
37
|
3 to delete, 1 to review, across 1 repository.
|
|
41
38
|
```
|
|
42
39
|
|
|
40
|
+
The words it uses (phases, rows, verdicts, risks, scope, landed) are defined
|
|
41
|
+
in [the terms](docs/planning/terms.md), and the design is
|
|
42
|
+
[D-4CE9](docs/planning/decisions/D-4CE9-the-cli-by-use-case.md).
|
|
43
|
+
|
|
43
44
|
On a terminal, the report and the preview are colored: red for a delete,
|
|
44
45
|
blue for a prune, yellow for a review, a blocked or a skipped row, green for a
|
|
45
46
|
keep. `NO_COLOR` turns this off; a pipe or a file gets no color unless
|
|
@@ -89,19 +90,350 @@ nvm users in fish can use a fish port such as `nvm.fish`; fnm has
|
|
|
89
90
|
with `type repo-cleaner`.
|
|
90
91
|
|
|
91
92
|
|
|
92
|
-
##
|
|
93
|
+
## Recipes
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
Each recipe is something a person would say, the command, and what happens.
|
|
96
|
+
Every command here runs in `tests/recipes.test.ts`, so a recipe that stops
|
|
97
|
+
working fails the build.
|
|
98
|
+
|
|
99
|
+
### Starting out
|
|
100
|
+
|
|
101
|
+
**"What is this, and how do I use it?"**
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
$ repo-cleaner
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Explains the phases and exits 2: nothing ran. `repo-cleaner --help` shows the
|
|
108
|
+
same and exits 0; `repo-cleaner <phase> --help` shows a phase's options, and
|
|
109
|
+
`--help --extended` the full reference.
|
|
110
|
+
|
|
111
|
+
### Looking
|
|
112
|
+
|
|
113
|
+
**"What can I clean up here?"**
|
|
114
|
+
|
|
115
|
+
```console
|
|
116
|
+
$ repo-cleaner status
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This repository's worktrees and local branches, each with a verdict, the
|
|
120
|
+
reason and the exact git command that would delete it. No network. Run from
|
|
121
|
+
anywhere inside the checkout.
|
|
122
|
+
|
|
123
|
+
**"…and on the remote too."**
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
$ repo-cleaner status --remote
|
|
127
|
+
$ repo-cleaner status --all
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`--remote` is the default remote's branches (usually `origin`); `--all` is
|
|
131
|
+
local and the default remote's branches. Each fetches the remote first and
|
|
132
|
+
looks up pull requests, because a remote branch can only be judged against
|
|
133
|
+
the remote as it is now.
|
|
134
|
+
|
|
135
|
+
**"Across every project I have."**
|
|
136
|
+
|
|
137
|
+
```console
|
|
138
|
+
$ repo-cleaner status ~/Developer
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
A directory that is not a checkout is searched for checkouts. Every phase
|
|
142
|
+
takes the same targets; see [Targets](#targets).
|
|
143
|
+
|
|
144
|
+
**"Which worktrees take the most disk?"**
|
|
145
|
+
|
|
146
|
+
```console
|
|
147
|
+
$ repo-cleaner status --worktrees --sizes
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Reads each worktree's size with `du -sk` (disk usage, not apparent size),
|
|
151
|
+
lists rows largest first within each verdict, and ends the totals line with
|
|
152
|
+
what the `delete` and `review` rows would free; `--format json` has each size
|
|
153
|
+
as `evidence.sizeBytes` and the totals as `reclaimableBytes`. Slower: it reads
|
|
154
|
+
every file under every worktree. A worktree whose `du` fails or runs past 60 s
|
|
155
|
+
shows `?` (`sizeBytes: null`) and keeps its verdict; the totals line counts
|
|
156
|
+
those `delete` and `review` ones as "not measured", so its bytes read as lower
|
|
157
|
+
bounds, and a `du` that hit an unreadable file still gives its total, also a
|
|
158
|
+
lower bound. Branch and remote rows have no size. Only `status` takes
|
|
159
|
+
`--sizes`; `plan` and `clean` refuse it, and `clean` measures each worktree
|
|
160
|
+
it removes without being asked.
|
|
161
|
+
|
|
162
|
+
### Cleaning
|
|
163
|
+
|
|
164
|
+
**"Just clean it up."** Immediate, still safe:
|
|
165
|
+
|
|
166
|
+
```console
|
|
167
|
+
$ repo-cleaner clean -y
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Deletes every local row judged `delete`, without asking. `review`, `keep` and
|
|
171
|
+
`blocked` rows are never touched. Before each delete it checks the row again
|
|
172
|
+
and deletes only the commit it saw.
|
|
173
|
+
|
|
174
|
+
**"Clean, but show me first."**
|
|
175
|
+
|
|
176
|
+
```console
|
|
177
|
+
$ repo-cleaner clean
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Shows the steps and asks:
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
/Users/me/work/api
|
|
184
|
+
delete branch:fix/login-redirect
|
|
185
|
+
git update-ref -d refs/heads/fix/login-redirect 3f9c2e1d…
|
|
186
|
+
prune worktree:/Users/me/work/wt/old
|
|
187
|
+
git -C /Users/me/work/api worktree remove /Users/me/work/wt/old
|
|
188
|
+
skip worktree:/Users/me/work/wt/spike
|
|
189
|
+
needs-pick: review: clean but no clear disposability signal; pick it to run it
|
|
190
|
+
|
|
191
|
+
would delete: 1 local branch, 1 stale worktree pruned
|
|
192
|
+
skipped 1, not deleted: 1 needs-pick (name with --pick)
|
|
193
|
+
Delete 2 items? [y/N]
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`clean` throws away anything typed while the sweep ran, so a key pressed
|
|
197
|
+
early cannot answer the question, and says so when it did. Once it has run,
|
|
198
|
+
it reports the disk space the removed worktrees freed (`freed: 4.2 GB (2
|
|
199
|
+
worktrees)`), each measured with `du` just before it was removed.
|
|
200
|
+
|
|
201
|
+
With no terminal to ask on (a script, an agent), it refuses unless `-y` is
|
|
202
|
+
given. It throws away anything typed while it looked, so a key pressed early
|
|
203
|
+
cannot answer the question.
|
|
204
|
+
|
|
205
|
+
**"Only local", "only the remote", "both".**
|
|
206
|
+
|
|
207
|
+
```console
|
|
208
|
+
$ repo-cleaner clean --local -y
|
|
209
|
+
$ repo-cleaner clean --remote -y
|
|
210
|
+
$ repo-cleaner clean --all -y
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`--local` (the default) is worktrees and local branches; `--remote` the
|
|
214
|
+
default remote's branches only; `--all` both. Narrower: `--worktrees`,
|
|
215
|
+
`--branches`. Scope flags add up: `--worktrees --remote` is worktrees and the
|
|
216
|
+
default remote's branches.
|
|
217
|
+
|
|
218
|
+
**"I just merged my PR: clean up that branch everywhere."**
|
|
219
|
+
|
|
220
|
+
```console
|
|
221
|
+
$ repo-cleaner clean --branch feat/login --all -y
|
|
222
|
+
$ repo-cleaner clean --branch HEAD --all -y
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Its worktree, its local branch and its remote branch, each if it is `delete`.
|
|
226
|
+
`HEAD` is the branch checked out here.
|
|
227
|
+
|
|
228
|
+
**"What exactly would it do?"**
|
|
229
|
+
|
|
230
|
+
```console
|
|
231
|
+
$ repo-cleaner clean --all --dry-run
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The same checks and the same step list as a real run; deletes nothing.
|
|
235
|
+
|
|
236
|
+
### Choosing remotes
|
|
237
|
+
|
|
238
|
+
**"Clean a remote other than origin."**
|
|
239
|
+
|
|
240
|
+
```console
|
|
241
|
+
$ repo-cleaner clean --remote=upstream -y
|
|
242
|
+
$ repo-cleaner clean --remote --remote=upstream -y
|
|
243
|
+
$ repo-cleaner clean --local --remote=upstream -y
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
A bare `--remote` is the default remote: `origin` if there is one, else the
|
|
247
|
+
remote the default branch tracks, else the only remote; with several remotes
|
|
248
|
+
and none of those, it is refused and asks for a name. Another remote is named
|
|
249
|
+
with `=`, and `--remote` is repeatable. `--all` with `--remote=<name>` is
|
|
250
|
+
refused: write `--local --remote=<name>`.
|
|
251
|
+
|
|
252
|
+
`--remote upstream`, with a space, reads `upstream` as a target. When no
|
|
253
|
+
directory of that name exists but a remote does, it is refused (exit 2) with
|
|
254
|
+
the fix: `upstream is a remote, not a directory: write --remote=upstream`.
|
|
255
|
+
|
|
256
|
+
**"Clean my fork's branches that landed upstream."**
|
|
257
|
+
|
|
258
|
+
```console
|
|
259
|
+
$ repo-cleaner clean --remote --against upstream -y
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Here `origin`, the default remote, is your fork, and `upstream` the original
|
|
263
|
+
project. Without `--against`, each remote's branches are judged against that
|
|
264
|
+
remote's own default branch, and your fork's `main` is usually stale, so
|
|
265
|
+
merged work would look unmerged. `--against upstream` judges every row
|
|
266
|
+
against `upstream/main` instead; the fork's own `main` is still kept.
|
|
267
|
+
|
|
268
|
+
A pull request belongs to the repository it targets, so the PRs opened from a
|
|
269
|
+
fork live in its parent. For a fork on GitHub, the parent's pull requests
|
|
270
|
+
whose head repository is the fork are listed too: an open one keeps the
|
|
271
|
+
branch, one merged at the branch's exact commit proves it landed, and with
|
|
272
|
+
none the branch is judged on git evidence, with no `confirm-open-pr`. A
|
|
273
|
+
parent listing that fails or reaches its cap keeps that gate.
|
|
274
|
+
|
|
275
|
+
**"Every remote."**
|
|
276
|
+
|
|
277
|
+
```console
|
|
278
|
+
$ repo-cleaner status --remote='*'
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Every configured remote, each fetched, and each remote's branches judged
|
|
282
|
+
against its own default branch. Where remotes are separate homes (a GitHub
|
|
283
|
+
`origin` and a company GitLab `internal`, each merging its own branches), a
|
|
284
|
+
branch merged into `internal/main` is `delete` without any flag.
|
|
285
|
+
|
|
286
|
+
### Deciding the unclear ones
|
|
287
|
+
|
|
288
|
+
**"Let me choose."**
|
|
289
|
+
|
|
290
|
+
```console
|
|
291
|
+
$ repo-cleaner clean -i
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
A checklist of the rows: `delete` rows ticked, `review` rows not, `keep` and
|
|
295
|
+
`blocked` rows shown but not selectable. Type item numbers or ranges to
|
|
296
|
+
toggle them, and Enter to accept. Ticking a row with a risk asks for the risk
|
|
297
|
+
by name. Needs a terminal.
|
|
298
|
+
|
|
299
|
+
**"Delete this one too; I've checked it."**
|
|
300
|
+
|
|
301
|
+
```console
|
|
302
|
+
$ repo-cleaner clean --pick feat/spike -y
|
|
303
|
+
$ repo-cleaner clean --pick feat/spike --allow abandon-unmerged -y
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
A `review` row runs only when picked. A row that would lose something
|
|
307
|
+
carries a named risk, and is skipped until that risk is allowed; see
|
|
308
|
+
[Pick and spare](#pick-and-spare) and [Rows, verdicts and
|
|
309
|
+
risks](#rows-verdicts-and-risks).
|
|
310
|
+
|
|
311
|
+
**"Never touch these."**
|
|
312
|
+
|
|
313
|
+
```console
|
|
314
|
+
$ repo-cleaner clean --all --spare 'release/*' --spare staging -y
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`--spare` takes a row or a glob.
|
|
318
|
+
|
|
319
|
+
**"Delete it, but keep a copy of the unfinished work."**
|
|
320
|
+
|
|
321
|
+
```console
|
|
322
|
+
$ repo-cleaner clean --pick feat/spike --archive --allow discard-archived -y
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Before deleting, pushes the row's unlanded commits and uncommitted files to an
|
|
326
|
+
archive branch on the default remote, checks it is there, then deletes; see
|
|
327
|
+
[Archive before delete](#archive-before-delete).
|
|
328
|
+
|
|
329
|
+
### Working with others and with machines
|
|
330
|
+
|
|
331
|
+
**"Plan now, clean later, or hand it to someone."**
|
|
332
|
+
|
|
333
|
+
```console
|
|
334
|
+
$ repo-cleaner plan --all -o plan.json
|
|
335
|
+
$ repo-cleaner clean --plan plan.json -y
|
|
100
336
|
```
|
|
101
337
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
338
|
+
The plan records each row's evidence. `clean --plan` checks every row again
|
|
339
|
+
against the repository as it is then, and drops any that changed. The plan
|
|
340
|
+
fixes what is cleaned, so targets and scope flags are refused with `--plan`;
|
|
341
|
+
`--pick`, `--spare` and `--allow` still choose among its rows. `--plan -`
|
|
342
|
+
reads the plan from stdin. The receipt is written beside the plan file. See
|
|
343
|
+
[Plan and clean](#plan-and-clean).
|
|
344
|
+
|
|
345
|
+
**"An agent or a script needs to read it."**
|
|
346
|
+
|
|
347
|
+
```console
|
|
348
|
+
$ repo-cleaner status --format json
|
|
349
|
+
$ repo-cleaner clean --all -y --format json
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
No prompts without a terminal, a JSON report or receipt on stdout, and
|
|
353
|
+
[exit codes](#exit-codes) that say what happened.
|
|
354
|
+
|
|
355
|
+
**"No network."**
|
|
356
|
+
|
|
357
|
+
```console
|
|
358
|
+
$ repo-cleaner status --all --offline
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Judges remote branches from the remote-tracking refs on disk. `clean` still
|
|
362
|
+
asks the remote before deleting a remote branch, and refuses if it cannot. See
|
|
363
|
+
[`--offline` reads what is already on disk](#--offline-reads-what-is-already-on-disk).
|
|
364
|
+
|
|
365
|
+
**"A remote I have no checkout of."**
|
|
366
|
+
|
|
367
|
+
```console
|
|
368
|
+
$ repo-cleaner clean https://github.com/acme/app.git --dry-run
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Remote branches only, through a clone kept in a cache; see [A remote with no
|
|
372
|
+
checkout](#a-remote-with-no-checkout).
|
|
373
|
+
|
|
374
|
+
## The grammar
|
|
375
|
+
|
|
376
|
+
```text
|
|
377
|
+
repo-cleaner explain the phases; run nothing
|
|
378
|
+
repo-cleaner status [target...] [what] [how sure] [output] look
|
|
379
|
+
repo-cleaner plan [target...] [what] [how sure] -o <file> save a plan
|
|
380
|
+
repo-cleaner clean [target...] [what] [how sure] [which] [go] delete
|
|
381
|
+
repo-cleaner clean --plan <file|-> [which] [go] delete what a plan saved
|
|
382
|
+
repo-cleaner cache [list | remove <url>...] the clone cache
|
|
383
|
+
repo-cleaner dev run a development checkout
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
| Group | Flag | Meaning |
|
|
387
|
+
|---|---|---|
|
|
388
|
+
| what | `--local` | Worktrees and local branches. The default when no scope flag is given. |
|
|
389
|
+
| | `--remote` | Branches on the default remote: `origin`, else the one the default branch tracks, else the only one. |
|
|
390
|
+
| | `--remote=<name>` | Branches on this remote; `*` is every remote. Repeatable, and combines with a bare `--remote`. |
|
|
391
|
+
| | `--all` | `--local` and `--remote`. |
|
|
392
|
+
| | `--worktrees`, `--branches` | Only worktrees, or only local branches. |
|
|
393
|
+
| | `--max-depth <n>` | How many levels below a directory target a checkout may sit and still be found. Default 3: `repos/<owner>/<repo>` from `~/dev`. A whole number, 1 or more. |
|
|
394
|
+
| how sure | `--fetch` | Fetch the default remote before judging local rows. Off by default. |
|
|
395
|
+
| | `--offline` | No fetch; judge from the refs on disk. Pull requests are still looked up; add `--provider none` for no network at all. |
|
|
396
|
+
| | `--against <remote>` | Judge every row against this remote's default branch. Without it, each remote's branches are judged against their own remote's default branch, and local rows against the default remote's. |
|
|
397
|
+
| | `--provider <auto\|github\|gitlab\|none>` | Where pull requests come from. Default `auto`, by each remote's host. An explicit `github` or `gitlab` over remotes on different kinds of host is refused. |
|
|
398
|
+
| | `--branch <name\|HEAD>` | One branch's rows: its worktree, local branch and remote branches. Never a default branch. |
|
|
399
|
+
| which | `--pick <row>` | Also run this `review` row. Repeatable. |
|
|
400
|
+
| | `--spare <row\|glob>` | Leave these rows alone. Repeatable. |
|
|
401
|
+
| | `--allow <risk>[=<row>]` | Accept a risk, for every row or one. Repeatable. |
|
|
402
|
+
| | `--archive` | Push unlanded work to an archive branch before deleting. |
|
|
403
|
+
| | `--archive-exclude <glob>` | With `--archive`, leave these files out of a snapshot. Repeatable. |
|
|
404
|
+
| | `-i`, `--interactive` | Choose rows from a checklist. |
|
|
405
|
+
| go | `-y`, `--yes` | Delete without asking. |
|
|
406
|
+
| | `--dry-run` | Check and show the steps; delete nothing. |
|
|
407
|
+
| | `--receipt <file>` | Where the receipt goes. Default: beside a `--plan` file, else none. |
|
|
408
|
+
| output | `--format <text\|json\|summary\|commands>` | `status`: default `text`; `commands` is only the safe delete commands, for a script. `clean`: `text` or `json`. |
|
|
409
|
+
| | `--all-rows` | `status` also shows `keep` rows. |
|
|
410
|
+
| | `--sizes` | `status` only. Read each worktree's size on disk, list rows largest first within each verdict, and total what the `delete` and `review` rows would free. Slower. |
|
|
411
|
+
| | `--no-progress` | No progress line on stderr. |
|
|
412
|
+
| | `-o, --out <file>` | `plan`: where the plan goes; `-` (the default) is stdout, and the totals go to stderr. |
|
|
413
|
+
|
|
414
|
+
`status --format summary` counts rows per repository:
|
|
415
|
+
|
|
416
|
+
```console
|
|
417
|
+
$ repo-cleaner status --all --format summary
|
|
418
|
+
/Users/me/work/api (acme/api, default main, origin)
|
|
419
|
+
total merged delete prune review blocked keep
|
|
420
|
+
local branches 12 8 6 0 1 0 5
|
|
421
|
+
worktrees 4 3 1 1 0 1 1
|
|
422
|
+
remote branches 40 31 30 0 6 0 4
|
|
423
|
+
|
|
424
|
+
37 to delete, 1 to prune, 7 to review, 1 blocked, across 1 repository.
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`prune` counts worktree rows whose directory is gone, or is no longer a
|
|
428
|
+
checkout: deleting one drops the stale record, with `git worktree remove
|
|
429
|
+
<path>` for a directory that is gone (that worktree's record alone) and the
|
|
430
|
+
repository-wide `git worktree prune` for one left without its `.git`, and a
|
|
431
|
+
directory that is still there stays. `merged` counts rows whose work is on the
|
|
432
|
+
default branch, by ancestry, by a merged PR at the branch's head, or by a patch
|
|
433
|
+
match; the default branch and the primary worktree are counted in `total` but
|
|
434
|
+
not judged.
|
|
435
|
+
|
|
436
|
+
## Reference
|
|
105
437
|
|
|
106
438
|
### Targets
|
|
107
439
|
|
|
@@ -110,7 +442,7 @@ A target is what to sweep:
|
|
|
110
442
|
| Target | Swept |
|
|
111
443
|
| --- | --- |
|
|
112
444
|
| a checkout | that repository; a linked worktree sweeps the repository it belongs to |
|
|
113
|
-
| a directory | every checkout found under it, three levels deep at most |
|
|
445
|
+
| a directory | every checkout found under it, three levels deep at most; `--max-depth` changes that |
|
|
114
446
|
| a remote URL (`https://`, `ssh://`, `file://`, `user@host:path`) | its remote branches only, through a clone kept in the cache directory (see [A remote with no checkout](#a-remote-with-no-checkout)) |
|
|
115
447
|
|
|
116
448
|
No target is the same as naming the current directory: at a checkout's root
|
|
@@ -137,116 +469,83 @@ target pointing at the wrong directory gets caught. A search that passes
|
|
|
137
469
|
10,000 directories says so on stderr while it is still running. A target that
|
|
138
470
|
resolves to nothing is reported rather than dropped.
|
|
139
471
|
|
|
140
|
-
###
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<path>` for a directory that is gone (that worktree's record alone) and the
|
|
181
|
-
repository-wide `git worktree prune` for one left without its `.git`, and a
|
|
182
|
-
directory that is still there stays. `merged` counts rows whose work is on
|
|
183
|
-
the default branch, by ancestry, by a merged PR at the branch's head, or by a
|
|
184
|
-
patch match; the default branch and the primary worktree are counted in
|
|
185
|
-
`total` but not judged.
|
|
186
|
-
|
|
187
|
-
### `repo-cleaner plan`
|
|
188
|
-
|
|
189
|
-
Sweeps and saves every row, each with a fingerprint of the evidence behind its
|
|
190
|
-
verdict, so it can be reviewed now and run later with
|
|
191
|
-
`clean --plan`. `-o, --out <file>` sets where it goes; the default, `-`, is
|
|
192
|
-
stdout, and the totals line goes to stderr.
|
|
193
|
-
|
|
194
|
-
### `repo-cleaner clean`
|
|
195
|
-
|
|
196
|
-
Sweeps (or reads `--plan`), checks every row again, shows the steps, asks,
|
|
197
|
-
then deletes, compare-and-swap, verifying each step and stopping at the first
|
|
198
|
-
failure. Without `--pick` it runs every row judged `delete`.
|
|
199
|
-
|
|
200
|
-
| Option | Meaning |
|
|
201
|
-
| --- | --- |
|
|
202
|
-
| `--pick <row>` | Work on exactly these rows. See [Pick and spare](#pick-and-spare). Repeatable. |
|
|
203
|
-
| `--spare <row>` | Leave this row alone, and make sure it is what you saw. Repeatable. |
|
|
204
|
-
| `--allow <risk>` | Accept this risk for every row that carries it. |
|
|
205
|
-
| `--allow <risk>=<row>` | Accept it for that one row only. |
|
|
206
|
-
| `--plan <file\|->` | Run a saved plan instead of sweeping now (`-` reads stdin). Rows whose evidence changed since the plan are dropped, not deleted. |
|
|
207
|
-
| `-y, --yes` | Do not ask. Without it, and with no terminal to ask on, `clean` refuses. |
|
|
208
|
-
| `--dry-run` | Check and show the steps, then stop. |
|
|
209
|
-
| `--receipt <file>` | Write a record of every step, rewritten after each one. Default: next to a `--plan` file; none otherwise. |
|
|
210
|
-
| `--format text\|json` | How the steps and the outcome are shown. |
|
|
472
|
+
### Archive before delete
|
|
473
|
+
|
|
474
|
+
Deleting a worktree with uncommitted files, or a branch with unpushed commits,
|
|
475
|
+
loses that work unless you allow `abandon-unmerged` or `discard-changes` and
|
|
476
|
+
accept the loss. With `--archive`, the run's first step per repository pushes
|
|
477
|
+
the work to the repository's own remote, checks with `ls-remote` that the
|
|
478
|
+
branch is there, and only then deletes:
|
|
479
|
+
|
|
480
|
+
1. Each accepted branch or remote branch with unlanded commits contributes its
|
|
481
|
+
tip. Each accepted worktree with unpushed commits contributes HEAD.
|
|
482
|
+
2. Each accepted worktree with modified, staged or untracked files contributes
|
|
483
|
+
a snapshot commit, built in a temporary index (`GIT_INDEX_FILE`) on top of
|
|
484
|
+
HEAD, so the worktree's own index and files are not touched.
|
|
485
|
+
3. One archive commit has the remote default branch's tree and, as parents,
|
|
486
|
+
the default branch's tip and everything contributed. Its message names the
|
|
487
|
+
source of each parent and the files left out.
|
|
488
|
+
4. It is pushed to `refs/heads/archive/<repo>-local-<YYYY-MM-DD>`, with `-2`,
|
|
489
|
+
`-3` and so on when that branch exists. If the push or the check fails, the
|
|
490
|
+
run stops before any delete and the receipt is `failed` at the `archive`
|
|
491
|
+
step. The step records the ref, the sha and, for each parent, the rows it
|
|
492
|
+
holds.
|
|
493
|
+
|
|
494
|
+
`--allow discard-archived` then takes the place of `abandon-unmerged` and
|
|
495
|
+
`discard-changes` on a row whose work the archive holds. The row is still
|
|
496
|
+
`review` and still runs only when picked. It keeps its own risk where the
|
|
497
|
+
archive does not hold the work:
|
|
498
|
+
|
|
499
|
+
- A worktree with a file the snapshot leaves out keeps `discard-changes`.
|
|
500
|
+
Left out: ignored files, secret-shaped files (`.env*`, `*.pem`, `*.key`,
|
|
501
|
+
`id_rsa*`, `id_ed25519*`), files matching `--archive-exclude`, and files
|
|
502
|
+
over 10 MiB (`maxFileBytes` in the library).
|
|
503
|
+
- A worktree with submodule commits, stashes or files keeps `abandon-unmerged`
|
|
504
|
+
and `discard-changes`: the archive holds none of them. Neither does it hold
|
|
505
|
+
the worktree's stashes. A worktree whose directory is gone has nothing to
|
|
506
|
+
snapshot.
|
|
507
|
+
|
|
508
|
+
An unattended run should not grant `discard-archived`.
|
|
509
|
+
|
|
510
|
+
To restore from an archive, fetch it and read the parent that holds your work.
|
|
511
|
+
The message of the archive commit lists the parents; the receipt records them:
|
|
211
512
|
|
|
212
|
-
```
|
|
213
|
-
/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
git -C /Users/me/work/api worktree remove /Users/me/work/wt/old
|
|
218
|
-
skip worktree:/Users/me/work/wt/spike
|
|
219
|
-
needs-pick: review: clean but no clear disposability signal; pick it to run it
|
|
220
|
-
|
|
221
|
-
would delete: 1 local branch, 1 stale worktree pruned
|
|
222
|
-
skipped 1, not deleted: 1 needs-pick (name with --pick)
|
|
223
|
-
Delete 2 items? [y/N]
|
|
513
|
+
```sh
|
|
514
|
+
git fetch origin archive/api-local-2026-11-19
|
|
515
|
+
git log -1 --format=%B FETCH_HEAD # which parent is which
|
|
516
|
+
git worktree add ../restored FETCH_HEAD^2 # parent 2, a snapshot or a tip
|
|
517
|
+
git branch spike/cache FETCH_HEAD^3 # or keep a parent as a branch
|
|
224
518
|
```
|
|
225
519
|
|
|
226
|
-
|
|
227
|
-
|
|
520
|
+
The archive commit needs a git identity; without one configured, it is
|
|
521
|
+
written as `repo-cleaner`. Pruning old archive branches is not done here.
|
|
228
522
|
|
|
229
523
|
### Pick and spare
|
|
230
524
|
|
|
231
|
-
**`--pick <row>`** means "
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
action (a branch with an open pull request), is deleted only when it is
|
|
238
|
-
named, so a borderline row never goes as part of a batch.
|
|
525
|
+
**`--pick <row>`** means "also run this row". `clean` deletes the rows judged
|
|
526
|
+
`delete`; a `review` row, or a `keep` row with an action (a branch with an
|
|
527
|
+
open pull request), is deleted only when it is picked, so a borderline row
|
|
528
|
+
never goes as part of a batch. To leave rows out, spare them. The library's
|
|
529
|
+
`select` takes an exact list of rows instead, for a checklist or a host that
|
|
530
|
+
chose the rows itself.
|
|
239
531
|
|
|
240
532
|
Picking does not approve anything: a picked row that carries a risk still
|
|
241
533
|
needs `--allow` for it. A `blocked` row, or a `keep` row with no action, is
|
|
242
534
|
skipped and shown with the reason.
|
|
243
535
|
|
|
244
536
|
**`--spare <row>`** means "leave this row alone, and make sure it is what I
|
|
245
|
-
saw".
|
|
537
|
+
saw". A bare name (`--spare staging`) is that branch everywhere: its
|
|
538
|
+
worktree, its local branch, and its remote branch on every remote; in a
|
|
539
|
+
repository without it, nothing. A glob (`--spare 'release/*'`, `--spare
|
|
540
|
+
'remote:origin/tmp-*'`) leaves every row it matches alone, by name, a remote
|
|
541
|
+
branch also by its name without the remote, and a worktree by the branch it
|
|
542
|
+
has out; `*` stays within a `/`, `**` does not. A glob that matches nothing
|
|
543
|
+
is no error. The usual case: delete a merged worktree and its local branch, but keep
|
|
246
544
|
the branch on the remote as a backup.
|
|
247
545
|
|
|
248
546
|
- A spared row is not deleted, even if it is judged `delete`.
|
|
249
|
-
- A
|
|
547
|
+
- A remote branch spared by its full name (`remote:origin/x` or `origin/x`),
|
|
548
|
+
not by a bare branch name or a glob, is still checked. If it is gone or its tip moved
|
|
250
549
|
since the plan, the run stops before deleting anything: you spared it for
|
|
251
550
|
what it held, so if that changed, the rest of the plan rests on a wrong
|
|
252
551
|
assumption. The run's first step checks the tip again with `git ls-remote`,
|
|
@@ -286,6 +585,7 @@ you approve them by name with `--allow`:
|
|
|
286
585
|
| --- | --- |
|
|
287
586
|
| `abandon-unmerged` | Commits not on the default branch and not captured by an exact-head merged PR, or a worktree's (or its submodules') commits and stashes that no remote has. `evidence.uniqueCommits` counts the commits. |
|
|
288
587
|
| `discard-changes` | Uncommitted or untracked files in the worktree or any of its submodules. |
|
|
588
|
+
| `discard-archived` | With `--archive`, stands for `abandon-unmerged` and `discard-changes` on a row whose work the archive holds. See [Archive before delete](#archive-before-delete). |
|
|
289
589
|
| `confirm-open-pr` | The branch has an open pull request, or open pull requests could not be checked (the CLI is missing or signed out, or the listing failed) so one cannot be ruled out; deleting the remote branch closes it. |
|
|
290
590
|
|
|
291
591
|
A worktree's submodules are part of it: one `--allow` on the worktree row
|
|
@@ -296,7 +596,7 @@ A branch whose worktree is judged `delete` is not held by it: the sweep judges
|
|
|
296
596
|
the branch on its own and records the worktree's path in `evidence.worktree`,
|
|
297
597
|
so one run removes the worktree and then deletes the branch. `clean` deletes
|
|
298
598
|
such a branch only when the same run removes its worktree, and drops it as
|
|
299
|
-
`held` otherwise. With `--
|
|
599
|
+
`held` otherwise. With `--branches` no worktree is swept, so the branch
|
|
300
600
|
stays held.
|
|
301
601
|
|
|
302
602
|
### Refused combinations
|
|
@@ -312,19 +612,29 @@ anything is swept; a row named two ways (a bare name and its id), and an
|
|
|
312
612
|
|
|
313
613
|
| Combination | Why |
|
|
314
614
|
| --- | --- |
|
|
615
|
+
| No phase named | The bare command explains the phases and runs nothing |
|
|
616
|
+
| A target that is no directory but a remote's name | `--remote upstream` with a space; write `--remote=upstream` |
|
|
617
|
+
| `--all` with `--remote=<name>` | `--all` is the default remote; write `--local --remote=<name>` |
|
|
315
618
|
| The same row in `--pick` and `--spare` | Asks for the row to be deleted and kept |
|
|
316
|
-
| `--allow <risk>=<row>` for a spared row
|
|
317
|
-
|
|
|
619
|
+
| `--allow <risk>=<row>` for a spared row | Approves deleting something that will not be deleted |
|
|
620
|
+
| `-i` with `--pick`, or with `--plan -`; `-i` without a terminal | The checklist chooses the rows, on the terminal |
|
|
621
|
+
| A picked or spared row of a kind the scope leaves out | The row cannot be in the run |
|
|
318
622
|
| A picked or spared row that is not one of `--branch`'s rows | The same |
|
|
319
|
-
| `--branch` with more than one target, with a remote URL, or naming
|
|
320
|
-
| `--plan` with targets or sweep options | The plan already fixed what is swept |
|
|
623
|
+
| `--branch` with more than one target, with a remote URL, or naming a default branch | `--branch` means one branch of one checkout, and a default branch is never a candidate |
|
|
624
|
+
| `--plan` with targets, scope flags or sweep options | The plan already fixed what is swept |
|
|
321
625
|
| `--plan -` without `--yes` or `--dry-run` | stdin carries the plan, so nothing can ask |
|
|
322
626
|
| `--yes` with `--dry-run` | One deletes without asking, the other deletes nothing |
|
|
323
627
|
| `--receipt` with `--dry-run` | Nothing runs, so there is nothing to record |
|
|
324
|
-
| `--
|
|
325
|
-
| `--
|
|
326
|
-
|
|
|
327
|
-
|
|
|
628
|
+
| `--archive-exclude` without `--archive`, or `--allow discard-archived` without `--archive` | There is no archive for them to act on |
|
|
629
|
+
| `--fetch` with `--offline`, or with remote rows only | They contradict, or remote rows fetch anyway |
|
|
630
|
+
| `--offline` or `--provider` without remote rows | Nothing is fetched or looked up without them |
|
|
631
|
+
| A remote URL target with `--local`, `--worktrees` or `--branches`, with `--offline`, or mixed with checkout targets | A remote URL has only remote branches, and it is fetched to be swept |
|
|
632
|
+
| `--all-rows` with any `--format` but `text` | `--all-rows` shows keep rows in the text report only |
|
|
633
|
+
|
|
634
|
+
A repository that cannot be judged as asked is an error row, and the rest are
|
|
635
|
+
still swept: a `--remote=<name>` or `--against` remote it does not have, a
|
|
636
|
+
bare `--remote` where several remotes leave no default, and an explicit
|
|
637
|
+
`--provider github` or `gitlab` over remotes on different kinds of host.
|
|
328
638
|
|
|
329
639
|
Refused after the sweep, before deleting, with exit 1:
|
|
330
640
|
|
|
@@ -343,12 +653,12 @@ Allowed, because nothing contradicts:
|
|
|
343
653
|
| `--allow <risk>` with `--allow <risk>=<row>` | The broader one covers it |
|
|
344
654
|
| `--allow` for a risk no row that runs carries | Runs; the preview lists it as `unused` |
|
|
345
655
|
| Picking a `blocked` or `keep` row | It is skipped and shown with the reason; the rest runs |
|
|
346
|
-
| `--
|
|
656
|
+
| A `--spare` glob that matches nothing | Nothing is spared by it |
|
|
347
657
|
|
|
348
658
|
### A remote with no checkout
|
|
349
659
|
|
|
350
660
|
```bash
|
|
351
|
-
repo-cleaner git@github.com:acme/api.git
|
|
661
|
+
repo-cleaner status git@github.com:acme/api.git
|
|
352
662
|
repo-cleaner clean git@github.com:acme/api.git
|
|
353
663
|
```
|
|
354
664
|
|
|
@@ -408,6 +718,18 @@ tracks a branch on a remote, other than the default branch (a branch made
|
|
|
408
718
|
with `--track` from `main` or `origin/main` does not count). With either, the worktree
|
|
409
719
|
is `delete`; with neither (`null`) it stays `review`.
|
|
410
720
|
|
|
721
|
+
A clean worktree whose HEAD is on a branch of the fetched remote is also
|
|
722
|
+
`delete`, whatever its PR state short of an open one (which keeps it), because the remote holds every commit. The
|
|
723
|
+
sweep must have fetched that remote (it is in scope, or `--fetch`, without
|
|
724
|
+
`--offline`): a local sweep's remote-tracking refs may name branches the remote
|
|
725
|
+
has deleted, so there the row keeps its verdict and a note says `--fetch` would
|
|
726
|
+
check. Every remote the sweep fetched counts. The default branch
|
|
727
|
+
does not count, the branch needs the same sign of use as above, and a dirty
|
|
728
|
+
worktree or one with submodule work is judged as before. `evidence.recoverableFrom`
|
|
729
|
+
lists the remote branches (`origin/topic`) and is part of the plan's
|
|
730
|
+
fingerprint. If a run also deletes every branch in that list, the worktree
|
|
731
|
+
needs `--allow abandon-unmerged`, since the run would remove the last copy.
|
|
732
|
+
|
|
411
733
|
Some worktrees are held back whatever their branch says and whatever is
|
|
412
734
|
allowed. Each lands in `row.blockers`, the row's verdict is `blocked`, and it
|
|
413
735
|
carries no command and no action:
|
|
@@ -541,11 +863,21 @@ reason, so a free-form reason such as `keep, build running` always blocks.
|
|
|
541
863
|
receipt records the `unlock-worktree` step.
|
|
542
864
|
- The owner is alive, or cannot be ruled out: `locked-worktree`.
|
|
543
865
|
- A lock writes `pid <N>` and, to guard against pid reuse, `start <time>`. The
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
866
|
+
start is read by [`@osdlc/file-lock`](../file-lock/README.md)'s
|
|
867
|
+
`sameProcess`, which takes:
|
|
868
|
+
- its `processIdentity`, the most reliable form: on Linux
|
|
869
|
+
`linux:<boot id>:<start ticks>`, checked against `/proc`, which neither a
|
|
870
|
+
clock change nor a time zone moves; elsewhere `start:<ms>`;
|
|
871
|
+
- a full ISO-8601 timestamp with a time of day and a zone
|
|
872
|
+
(`2026-10-25T18:22:19Z`; one with no zone is not accepted), epoch seconds
|
|
873
|
+
(9-10 digits) or epoch milliseconds (12-13 digits);
|
|
874
|
+
- the `ps -o lstart` form (`Sat Oct 25 18:22:19 2026`), which matches when it
|
|
875
|
+
is the real start in some time zone, since the writer's zone is unknown.
|
|
876
|
+
|
|
877
|
+
A pid is reused only after its owner exits, so only a live pid whose process
|
|
878
|
+
started more than two seconds after the recorded time is a reused pid and
|
|
879
|
+
counts as dead. A recorded time later than the start, such as when the
|
|
880
|
+
owner took the lock, still names the owner. Anything else, a date alone, a
|
|
549
881
|
short number or a partial date, cannot rule the owner out and the lock stays
|
|
550
882
|
a blocker.
|
|
551
883
|
- Only `ps` exiting 1 with no output and no error text means "no such pid".
|
|
@@ -556,7 +888,7 @@ reason, so a free-form reason such as `keep, build running` always blocks.
|
|
|
556
888
|
- Before the unlock and again before the remove, `clean` asks again, and reads
|
|
557
889
|
the process table afresh. If the owner is alive by then, or a process other
|
|
558
890
|
than an idle shell works in the directory, or the table cannot be read, the
|
|
559
|
-
step fails and the
|
|
891
|
+
step fails, and the steps that depend on it are skipped. A row dropped at the re-sweep touches nothing;
|
|
560
892
|
a step that fails at the unlock leaves the lock in place. `stale_lock` is part
|
|
561
893
|
of a worktree row's fingerprint, so a lock taken after the plan was written
|
|
562
894
|
drops the row too.
|
|
@@ -573,7 +905,10 @@ Both questions go to a `ProcessProbe` (`alive(pid, startedAt?)` and
|
|
|
573
905
|
`holders(path, { fresh? })`), passed as `probe` in the options of `sweep`,
|
|
574
906
|
`check` and `run`. The default, `defaultProcessProbe()`, runs
|
|
575
907
|
`ps -o lstart=`, `ps -A -o pid=,ppid=` and `lsof -d cwd` through
|
|
576
|
-
`@osdlc/command-seam`, and needs `ps` and `lsof` on `PATH`.
|
|
908
|
+
`@osdlc/command-seam`, and needs `ps` and `lsof` on `PATH`. `alive` first asks
|
|
909
|
+
`process.kill(pid, 0)`, so a gone pid costs no `ps`, and runs `ps` under
|
|
910
|
+
`TZ=UTC` and `LC_ALL=C` so the start time is one instant (a DST fall-back
|
|
911
|
+
cannot shift it). It reads the
|
|
577
912
|
process table once per probe and reuses it for every worktree: `sweep` makes
|
|
578
913
|
one probe per repository, and `run` uses one probe for its re-sweep and
|
|
579
914
|
reads the table afresh for each pre-unlock and pre-remove check. Where the
|
|
@@ -616,7 +951,7 @@ read. In 0.18 and earlier the repository came back as an error, and none of
|
|
|
616
951
|
it was judged:
|
|
617
952
|
|
|
618
953
|
```console
|
|
619
|
-
$ repo-cleaner --
|
|
954
|
+
$ repo-cleaner status --all --offline
|
|
620
955
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
621
956
|
error: GitHub has no such pull request, issue or repository, or you cannot see it.
|
|
622
957
|
|
|
@@ -626,7 +961,7 @@ $ repo-cleaner --remote --offline
|
|
|
626
961
|
Now the merged branch is still found, and the note says what was missing:
|
|
627
962
|
|
|
628
963
|
```console
|
|
629
|
-
$ repo-cleaner --
|
|
964
|
+
$ repo-cleaner status --all --offline
|
|
630
965
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
631
966
|
note: Listing PRs with `gh pr list` failed (GitHub has no such pull request, issue or repository, or you cannot see it.); judged on git evidence alone.
|
|
632
967
|
branch feat/login delete fully merged into origin/main
|
|
@@ -671,7 +1006,7 @@ The same happens when `gh` is not installed or not signed in. Nothing was
|
|
|
671
1006
|
asked, so nothing can rule out an open pull request:
|
|
672
1007
|
|
|
673
1008
|
```console
|
|
674
|
-
$ repo-cleaner --
|
|
1009
|
+
$ repo-cleaner status --all --offline
|
|
675
1010
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
676
1011
|
note: Could not check for open PRs: `gh` is not installed, so deleting a remote branch needs confirm-open-pr. Install `gh`, or pass `--allow confirm-open-pr` once you have checked.
|
|
677
1012
|
branch feat/login delete fully merged into origin/main
|
|
@@ -694,13 +1029,13 @@ no longer exists. In 0.18 and earlier it still called `git ls-remote`, and a
|
|
|
694
1029
|
remote that could not be read failed the whole repository:
|
|
695
1030
|
|
|
696
1031
|
```console
|
|
697
|
-
$ repo-cleaner --remote --offline --provider none
|
|
1032
|
+
$ repo-cleaner --remote --offline --provider none # 0.18 and earlier
|
|
698
1033
|
~/work/api (default main, origin, not fetched)
|
|
699
1034
|
error: git ls-remote: The remote '/srv/git/api.git' does not exist or is not a git repository. …
|
|
700
1035
|
```
|
|
701
1036
|
|
|
702
1037
|
```console
|
|
703
|
-
$ repo-cleaner --
|
|
1038
|
+
$ repo-cleaner status --all --offline --provider none # now
|
|
704
1039
|
~/work/api (default main, origin, not fetched)
|
|
705
1040
|
branch feat/login delete fully merged into origin/main
|
|
706
1041
|
git update-ref -d refs/heads/feat/login 255acd56…
|
|
@@ -722,7 +1057,7 @@ branch the remote no longer has is skipped as gone, and one whose tip moved
|
|
|
722
1057
|
is skipped too:
|
|
723
1058
|
|
|
724
1059
|
```console
|
|
725
|
-
$ repo-cleaner clean --remote --offline --provider none --
|
|
1060
|
+
$ repo-cleaner clean --remote --offline --provider none --yes
|
|
726
1061
|
skipped remote:origin/feat/search — gone (no longer in the sweep)
|
|
727
1062
|
ok remote:origin/feat/cart — git push … origin :refs/heads/feat/cart (ls-remote lists nothing)
|
|
728
1063
|
|
|
@@ -758,7 +1093,7 @@ The same information is on the result, for a host to show or act on:
|
|
|
758
1093
|
```ts
|
|
759
1094
|
import { sweep } from '@osdlc/repo-cleaner'
|
|
760
1095
|
|
|
761
|
-
const result = sweep(['.'], {
|
|
1096
|
+
const result = sweep(['.'], { remotes: [''], offline: true, provider: 'github' })
|
|
762
1097
|
for (const repo of result.repos) {
|
|
763
1098
|
if (repo.error !== null) {
|
|
764
1099
|
console.log(`${repo.path}: could not be swept: ${repo.error}`)
|
|
@@ -794,17 +1129,17 @@ The decision behind this is
|
|
|
794
1129
|
## Plan and clean
|
|
795
1130
|
|
|
796
1131
|
```bash
|
|
797
|
-
repo-cleaner clean #
|
|
798
|
-
repo-cleaner clean --
|
|
1132
|
+
repo-cleaner clean # look, show the steps, ask, delete
|
|
1133
|
+
repo-cleaner clean --worktrees --yes # no question
|
|
799
1134
|
repo-cleaner plan -o plan.json # save the plan to review or edit
|
|
800
1135
|
repo-cleaner clean --plan plan.json --pick branch:feat/x
|
|
801
1136
|
repo-cleaner plan | repo-cleaner clean --plan - --yes
|
|
802
1137
|
```
|
|
803
1138
|
|
|
804
1139
|
A plan holds every row with a fingerprint of the evidence behind its verdict,
|
|
805
|
-
and the sweep options it was made with.
|
|
806
|
-
|
|
807
|
-
|
|
1140
|
+
and the sweep options it was made with. The rows judged `delete` run, and
|
|
1141
|
+
the rows picked; the blocked and structural rows are there so a pick of one
|
|
1142
|
+
is skipped with its reason. `clean`
|
|
808
1143
|
either sweeps and plans in memory, or reads a plan with `--plan`. A plan of an
|
|
809
1144
|
older version is refused, not translated: sweep again.
|
|
810
1145
|
|
|
@@ -819,15 +1154,44 @@ plan's sweep did, so it judges against the same, current default branch.
|
|
|
819
1154
|
|
|
820
1155
|
On yes it runs only the steps it showed: spared remote tips first, then
|
|
821
1156
|
worktrees, local branches and remote branches, in that order. Branch
|
|
822
|
-
deletes are compare-and-swap
|
|
823
|
-
|
|
1157
|
+
deletes are compare-and-swap and every step is verified.
|
|
1158
|
+
|
|
1159
|
+
A step that fails is marked `failed`, and the steps that depend on it are
|
|
1160
|
+
marked `skipped`, with the failed step named in the receipt's `error`. Every
|
|
1161
|
+
other step runs, so one worktree that cannot be removed no longer leaves the
|
|
1162
|
+
rest undone.
|
|
1163
|
+
|
|
1164
|
+
| Failed step | Skipped | Why |
|
|
1165
|
+
| --- | --- | --- |
|
|
1166
|
+
| `verify-remote` (a spared tip moved or is gone) | every later step: the run stops | the plan's premise no longer holds |
|
|
1167
|
+
| `unlock-worktree` | that row's `remove-worktree` or `prune-worktrees` | it is still locked |
|
|
1168
|
+
| `remove-worktree`, `prune-worktrees` | the `delete-branch` of the branch that worktree held, and a repository-wide prune | the branch was deletable only because its worktree was going; the prune counted on the removal |
|
|
1169
|
+
| `delete-branch` | the same branch's `delete-remote` in the same repository | the remote copy may be the one the plan relied on |
|
|
1170
|
+
| any | nothing in another repository, and no unrelated row | independent |
|
|
1171
|
+
|
|
1172
|
+
A step skipped for a skipped step names the failed step at the root. The run
|
|
1173
|
+
still ends `failed` (exit `11`) when any step failed. Every run ends with what
|
|
1174
|
+
it did:
|
|
824
1175
|
|
|
825
1176
|
```text
|
|
826
1177
|
deleted: 1 worktree, 3 local branches, 2 remote branches, 1 stale worktree pruned
|
|
1178
|
+
freed: 1.3 GB (1 worktree)
|
|
827
1179
|
skipped 2, not deleted: 1 needs-pick (name with --pick), 1 duplicate
|
|
828
1180
|
status: complete
|
|
829
1181
|
```
|
|
830
1182
|
|
|
1183
|
+
A run with a failure adds a line such as `9 steps ran, 1 failed, 2 skipped`; a
|
|
1184
|
+
run stopped by a spared tip says how many rows did not run instead.
|
|
1185
|
+
|
|
1186
|
+
`freed` is the disk space of the worktrees the run removed, each read with
|
|
1187
|
+
`du -sk` just before its removal and kept on its `remove-worktree` step as
|
|
1188
|
+
`freedBytes` in the receipt. A failed removal frees nothing, and a pruned
|
|
1189
|
+
worktree's directory was already gone, so neither counts. A size `du` could
|
|
1190
|
+
not read (it failed, or ran past 60 s) is `freedBytes: null`, and the line
|
|
1191
|
+
says `freed: at least 4.2 GB (2 worktrees, 1 not measured)`. `--format json`
|
|
1192
|
+
carries the totals as `summary.freedBytes` and `summary.unmeasured`. A dry run
|
|
1193
|
+
measures nothing.
|
|
1194
|
+
|
|
831
1195
|
Two clones of one remote list the same remote branches; `clean` deletes each
|
|
832
1196
|
once and drops the other clone's row as `duplicate`, or as `spared` when the
|
|
833
1197
|
branch is spared through the other clone. Remotes are compared by the push URL
|
|
@@ -843,24 +1207,24 @@ that swept, or read its plan from stdin, writes a receipt only when
|
|
|
843
1207
|
|
|
844
1208
|
| Code | Meaning |
|
|
845
1209
|
| --- | --- |
|
|
846
|
-
| `0` |
|
|
1210
|
+
| `0` | Looked or saved; or `clean` ran, was declined, or had nothing to do |
|
|
847
1211
|
| `1` | Failed against the state it found: an unreadable plan, a row not in it, a spared branch that moved |
|
|
848
|
-
| `2` | Cannot run as typed: an unknown flag, a malformed row, a refused combination, `clean` with nobody to ask and no `--yes` |
|
|
1212
|
+
| `2` | Cannot run as typed: no phase named, an unknown flag, a malformed row, a refused combination, `clean` with nobody to ask and no `--yes` |
|
|
849
1213
|
| `10` | Nothing to sweep: no target named a repository |
|
|
850
|
-
| `11` | `clean`
|
|
1214
|
+
| `11` | `clean` had a failed step; the receipt says which, and which steps it skipped. A failed spared-tip check stops the run |
|
|
851
1215
|
|
|
852
1216
|
## As a library
|
|
853
1217
|
|
|
854
1218
|
```ts
|
|
855
1219
|
import { check, plan, render, run, sweep } from '@osdlc/repo-cleaner'
|
|
856
1220
|
|
|
857
|
-
const result = sweep(['/Users/me/work/api'], {
|
|
1221
|
+
const result = sweep(['/Users/me/work/api'], { remotes: [''] })
|
|
858
1222
|
for (const row of result.repos[0]?.rows ?? []) {
|
|
859
1223
|
console.log(row.id, row.verdict, row.why, row.risks)
|
|
860
1224
|
}
|
|
861
1225
|
|
|
862
1226
|
const preview = check(plan(result), {
|
|
863
|
-
|
|
1227
|
+
select: ['branch:spike/cache'],
|
|
864
1228
|
allow: [{ risk: 'abandon-unmerged', row: 'branch:spike/cache' }],
|
|
865
1229
|
})
|
|
866
1230
|
process.stdout.write(render.preview(preview))
|
|
@@ -869,12 +1233,16 @@ const receipt = run(preview)
|
|
|
869
1233
|
|
|
870
1234
|
| Export | What it does |
|
|
871
1235
|
| --- | --- |
|
|
872
|
-
| `sweep(targets, opts?)` | Resolve the targets and judge every row. Options as on the command line: `only`, `remote`, `offline`, `against`, `provider`, `branch`, plus `cwd`, `cacheDir`, `annotate`, `onProgress`, `onWarn`, and the injectable `git`, `gh`, `glab` runners and `probe` |
|
|
1236
|
+
| `sweep(targets, opts?)` | Resolve the targets and judge every row. Options as on the command line: `only`, `remotes` (a name, `''` for the default remote, `*` for every remote), `fetch`, `offline`, `against`, `provider`, `branch`, `sizes`, plus `sizeTimeoutMs`, `cwd`, `cacheDir`, `annotate`, `onProgress`, `onWarn`, and the injectable `git`, `gh`, `glab`, `du` runners and `probe` |
|
|
873
1237
|
| `plan(sweep)` | Every row, fingerprinted, with the sweep's options |
|
|
874
|
-
| `check(plan, approval, opts?)` | Resolve `{ pick, spare, allow }` against the plan, sweep again, and return a `Preview`: the steps, the rows dropped and why, the allows no row needed, and `notes`, what the re-check judged without. Deletes nothing |
|
|
875
|
-
| `run(preview, opts?)` | Sweep once more and take the preview's steps, writing a `Receipt` (to `receiptPath` after every step, when given). `onNotes` hears what its own re-check judged without |
|
|
1238
|
+
| `check(plan, approval, opts?)` | Resolve `{ select, pick, spare, allow }` against the plan, sweep again, and return a `Preview`: the steps, the rows dropped and why, the allows no row needed, and `notes`, what the re-check judged without. Deletes nothing |
|
|
1239
|
+
| `run(preview, opts?)` | Sweep once more and take the preview's steps, writing a `Receipt` (to `receiptPath` after every step, when given). `onNotes` hears what its own re-check judged without. Each worktree it removes is measured with `du` first, into the step's `freedBytes` |
|
|
876
1240
|
| `inspectWorktree(path, opts?)` | One worktree judged as a sweep judges it, submodules included |
|
|
877
|
-
| `
|
|
1241
|
+
| `candidatesOf(sweep)` | The sweep's deletable or objecting rows as plain data (`CleanCandidate`): id, kind, path, evidence, fingerprint, `requires`, blockers, risks |
|
|
1242
|
+
| `removeCandidate(candidate, opts?)` | Delete one candidate as `run` takes one row: archive first with `archive`, the live-process and unsafe-force checks, the removal, its verification. Returns a `CandidateRemoval` (`ok`, `steps`, `error`, and `archiveFailed` for a failed archive push, which a host should treat as fatal). Never throws for a refused or failed delete |
|
|
1243
|
+
| `readPlan`, `writePlan`, `PlanSchema` | Plans on disk |
|
|
1244
|
+
| `fingerprint`, `sameFingerprint` | The evidence a row rests on and the rule that compares two of them |
|
|
1245
|
+
| `writeJsonAtomic`, `busyHolders` | The atomic JSON write the receipt uses; the holders of a worktree that are not idle shells |
|
|
878
1246
|
| `render` | The command line's formats: `text`, `json`, `summary`, `commands`, `preview`, `receipt` |
|
|
879
1247
|
| `defaultProcessProbe`, `providers` | The defaults a host can wrap or replace |
|
|
880
1248
|
| `RepoCleanerError` | Every refusal, with a `code`: `conflict`, `bad-input`, `not-found`, `ambiguous`, `spared-changed`, `bad-plan` |
|
|
@@ -927,6 +1295,16 @@ host rarely has to veto one. It mostly sharpens the rows left at `keep` or
|
|
|
927
1295
|
`review`. A worktree the host holds back keeps its branch: the sweep applies
|
|
928
1296
|
that rule after the hook.
|
|
929
1297
|
|
|
1298
|
+
### Taking one candidate at a time
|
|
1299
|
+
|
|
1300
|
+
A host that runs its own phases (discover, object, re-check, delete) uses
|
|
1301
|
+
`candidatesOf` and `removeCandidate` instead of `plan`, `check` and `run`. The
|
|
1302
|
+
host re-checks a candidate by sweeping again and comparing `fingerprint` with
|
|
1303
|
+
`sameFingerprint`, and turns `blockers` and `risks` into its own objections. It
|
|
1304
|
+
deletes what a branch `requires` (its worktree) first. `removeCandidate` keeps the safety model of
|
|
1305
|
+
`run`: a risk not in `allow` is refused, and with `archive` the push is made
|
|
1306
|
+
and verified before the delete, one archive per candidate.
|
|
1307
|
+
|
|
930
1308
|
## Providers (prototype)
|
|
931
1309
|
|
|
932
1310
|
Pull request evidence comes from a provider. Classification reads the same
|
|
@@ -935,8 +1313,25 @@ branch.
|
|
|
935
1313
|
|
|
936
1314
|
| Provider | CLI | Listing |
|
|
937
1315
|
| --- | --- | --- |
|
|
938
|
-
| `github` | `gh` | `gh pr list --
|
|
939
|
-
| `gitlab` | `glab` | `glab api projects/<path>/merge_requests
|
|
1316
|
+
| `github` | `gh` | `gh pr list --repo <host>/<project>`: every open PR (up to 1000), then the newest 300 of any state |
|
|
1317
|
+
| `gitlab` | `glab` | `glab api projects/<path>/merge_requests`, 100 a page: every opened MR (up to 1000), then the newest 300 of any state |
|
|
1318
|
+
|
|
1319
|
+
Open PRs are what gate a delete, so they are read on their own and an old open
|
|
1320
|
+
one is found however many newer PRs there are. Merged and closed PRs past the
|
|
1321
|
+
newest 300 are not read; they only prove that work landed, so a branch whose
|
|
1322
|
+
merged PR is that old falls back to ancestry or a patch match. A listing that
|
|
1323
|
+
stops at the open-PR cap is incomplete.
|
|
1324
|
+
|
|
1325
|
+
The PRs a fork opens live in its parent, so for a fork on GitHub the parent's
|
|
1326
|
+
PRs whose head repository is the fork are listed too, under the same caps, and
|
|
1327
|
+
count for the fork's branches. A parent listing that fails or stops at a cap
|
|
1328
|
+
leaves the listing incomplete, as does a fork whose parent cannot be named.
|
|
1329
|
+
For an incomplete listing the repository carries a note, and a remote branch
|
|
1330
|
+
with no PR found needs `confirm-open-pr` to delete, as after a failed listing.
|
|
1331
|
+
|
|
1332
|
+
The GitHub provider names the repository the sweep judges (`--repo`), not the
|
|
1333
|
+
one `gh` would pick from the checkout's remotes, which prefers `upstream` over
|
|
1334
|
+
`origin`.
|
|
940
1335
|
|
|
941
1336
|
With `--remote`, `--provider auto` (the default) reads the remote's host: a
|
|
942
1337
|
remote that names no host (a local path or `file://`) gets no provider, since
|