@osdlc/repo-cleaner 0.20.5 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +545 -165
- package/dist/approval.d.ts +91 -0
- package/dist/approval.js +233 -0
- package/dist/archive.d.ts +87 -0
- package/dist/archive.js +252 -0
- package/dist/branches.d.ts +4 -4
- package/dist/branches.js +56 -43
- package/dist/clean.d.ts +30 -70
- package/dist/clean.js +251 -197
- package/dist/cli.d.ts +16 -10
- package/dist/cli.js +252 -103
- package/dist/discover.d.ts +28 -7
- package/dist/discover.js +185 -42
- package/dist/index.d.ts +6 -3
- package/dist/index.js +5 -2
- package/dist/landing.d.ts +10 -5
- package/dist/landing.js +15 -16
- package/dist/plan.d.ts +18 -11
- package/dist/plan.js +33 -13
- package/dist/processes.d.ts +19 -9
- package/dist/processes.js +51 -25
- package/dist/providers/github.d.ts +21 -3
- package/dist/providers/github.js +149 -27
- package/dist/providers/gitlab.js +37 -17
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/types.d.ts +15 -2
- package/dist/prs.d.ts +19 -10
- package/dist/prs.js +21 -13
- package/dist/receipt.d.ts +68 -3
- package/dist/receipt.js +30 -3
- package/dist/reference.d.ts +1 -1
- package/dist/reference.js +93 -50
- package/dist/remote-mirror.d.ts +2 -1
- package/dist/remote-mirror.js +3 -14
- package/dist/render.d.ts +17 -2
- package/dist/render.js +80 -13
- package/dist/scope.d.ts +15 -0
- package/dist/scope.js +125 -0
- package/dist/size.d.ts +20 -0
- package/dist/size.js +34 -0
- package/dist/status-line.js +1 -0
- package/dist/step-board.js +6 -4
- package/dist/sweep.d.ts +45 -18
- package/dist/sweep.js +151 -127
- package/dist/types.d.ts +89 -10
- package/dist/types.js +50 -6
- package/dist/util.d.ts +2 -0
- package/dist/util.js +25 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/dist/worktrees.js +87 -11
- package/package.json +6 -5
package/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,349 @@ 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
|
+
| how sure | `--fetch` | Fetch the default remote before judging local rows. Off by default. |
|
|
394
|
+
| | `--offline` | No fetch; judge from the refs on disk. Pull requests are still looked up; add `--provider none` for no network at all. |
|
|
395
|
+
| | `--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. |
|
|
396
|
+
| | `--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. |
|
|
397
|
+
| | `--branch <name\|HEAD>` | One branch's rows: its worktree, local branch and remote branches. Never a default branch. |
|
|
398
|
+
| which | `--pick <row>` | Also run this `review` row. Repeatable. |
|
|
399
|
+
| | `--spare <row\|glob>` | Leave these rows alone. Repeatable. |
|
|
400
|
+
| | `--allow <risk>[=<row>]` | Accept a risk, for every row or one. Repeatable. |
|
|
401
|
+
| | `--archive` | Push unlanded work to an archive branch before deleting. |
|
|
402
|
+
| | `--archive-exclude <glob>` | With `--archive`, leave these files out of a snapshot. Repeatable. |
|
|
403
|
+
| | `-i`, `--interactive` | Choose rows from a checklist. |
|
|
404
|
+
| go | `-y`, `--yes` | Delete without asking. |
|
|
405
|
+
| | `--dry-run` | Check and show the steps; delete nothing. |
|
|
406
|
+
| | `--receipt <file>` | Where the receipt goes. Default: beside a `--plan` file, else none. |
|
|
407
|
+
| output | `--format <text\|json\|summary\|commands>` | `status`: default `text`; `commands` is only the safe delete commands, for a script. `clean`: `text` or `json`. |
|
|
408
|
+
| | `--all-rows` | `status` also shows `keep` rows. |
|
|
409
|
+
| | `--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. |
|
|
410
|
+
| | `--no-progress` | No progress line on stderr. |
|
|
411
|
+
| | `-o, --out <file>` | `plan`: where the plan goes; `-` (the default) is stdout, and the totals go to stderr. |
|
|
412
|
+
|
|
413
|
+
`status --format summary` counts rows per repository:
|
|
414
|
+
|
|
415
|
+
```console
|
|
416
|
+
$ repo-cleaner status --all --format summary
|
|
417
|
+
/Users/me/work/api (acme/api, default main, origin)
|
|
418
|
+
total merged delete prune review blocked keep
|
|
419
|
+
local branches 12 8 6 0 1 0 5
|
|
420
|
+
worktrees 4 3 1 1 0 1 1
|
|
421
|
+
remote branches 40 31 30 0 6 0 4
|
|
422
|
+
|
|
423
|
+
37 to delete, 1 to prune, 7 to review, 1 blocked, across 1 repository.
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
`prune` counts worktree rows whose directory is gone, or is no longer a
|
|
427
|
+
checkout: deleting one drops the stale record, with `git worktree remove
|
|
428
|
+
<path>` for a directory that is gone (that worktree's record alone) and the
|
|
429
|
+
repository-wide `git worktree prune` for one left without its `.git`, and a
|
|
430
|
+
directory that is still there stays. `merged` counts rows whose work is on the
|
|
431
|
+
default branch, by ancestry, by a merged PR at the branch's head, or by a patch
|
|
432
|
+
match; the default branch and the primary worktree are counted in `total` but
|
|
433
|
+
not judged.
|
|
434
|
+
|
|
435
|
+
## Reference
|
|
105
436
|
|
|
106
437
|
### Targets
|
|
107
438
|
|
|
@@ -137,116 +468,83 @@ target pointing at the wrong directory gets caught. A search that passes
|
|
|
137
468
|
10,000 directories says so on stderr while it is still running. A target that
|
|
138
469
|
resolves to nothing is reported rather than dropped.
|
|
139
470
|
|
|
140
|
-
###
|
|
141
|
-
|
|
142
|
-
|
|
471
|
+
### Archive before delete
|
|
472
|
+
|
|
473
|
+
Deleting a worktree with uncommitted files, or a branch with unpushed commits,
|
|
474
|
+
loses that work unless you allow `abandon-unmerged` or `discard-changes` and
|
|
475
|
+
accept the loss. With `--archive`, the run's first step per repository pushes
|
|
476
|
+
the work to the repository's own remote, checks with `ls-remote` that the
|
|
477
|
+
branch is there, and only then deletes:
|
|
478
|
+
|
|
479
|
+
1. Each accepted branch or remote branch with unlanded commits contributes its
|
|
480
|
+
tip. Each accepted worktree with unpushed commits contributes HEAD.
|
|
481
|
+
2. Each accepted worktree with modified, staged or untracked files contributes
|
|
482
|
+
a snapshot commit, built in a temporary index (`GIT_INDEX_FILE`) on top of
|
|
483
|
+
HEAD, so the worktree's own index and files are not touched.
|
|
484
|
+
3. One archive commit has the remote default branch's tree and, as parents,
|
|
485
|
+
the default branch's tip and everything contributed. Its message names the
|
|
486
|
+
source of each parent and the files left out.
|
|
487
|
+
4. It is pushed to `refs/heads/archive/<repo>-local-<YYYY-MM-DD>`, with `-2`,
|
|
488
|
+
`-3` and so on when that branch exists. If the push or the check fails, the
|
|
489
|
+
run stops before any delete and the receipt is `failed` at the `archive`
|
|
490
|
+
step. The step records the ref, the sha and, for each parent, the rows it
|
|
491
|
+
holds.
|
|
492
|
+
|
|
493
|
+
`--allow discard-archived` then takes the place of `abandon-unmerged` and
|
|
494
|
+
`discard-changes` on a row whose work the archive holds. The row is still
|
|
495
|
+
`review` and still runs only when picked. It keeps its own risk where the
|
|
496
|
+
archive does not hold the work:
|
|
497
|
+
|
|
498
|
+
- A worktree with a file the snapshot leaves out keeps `discard-changes`.
|
|
499
|
+
Left out: ignored files, secret-shaped files (`.env*`, `*.pem`, `*.key`,
|
|
500
|
+
`id_rsa*`, `id_ed25519*`), files matching `--archive-exclude`, and files
|
|
501
|
+
over 10 MiB (`maxFileBytes` in the library).
|
|
502
|
+
- A worktree with submodule commits, stashes or files keeps `abandon-unmerged`
|
|
503
|
+
and `discard-changes`: the archive holds none of them. Neither does it hold
|
|
504
|
+
the worktree's stashes. A worktree whose directory is gone has nothing to
|
|
505
|
+
snapshot.
|
|
506
|
+
|
|
507
|
+
An unattended run should not grant `discard-archived`.
|
|
508
|
+
|
|
509
|
+
To restore from an archive, fetch it and read the parent that holds your work.
|
|
510
|
+
The message of the archive commit lists the parents; the receipt records them:
|
|
143
511
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
| `--branch <name\|HEAD>` | Only the rows of one branch: its worktree, its local branch, and its remote branch with `--remote`. `HEAD` is the branch checked out at the target. Never the default branch. |
|
|
150
|
-
| `--against <remote>` | The remote whose default branch counts as "merged into". Default: `origin`, then the first remote. |
|
|
151
|
-
| `--provider <name>` | With `--remote`: where pull requests come from. `auto` (by the remote's host), `github`, `gitlab`, or `none` to judge on git evidence alone. |
|
|
152
|
-
| `--no-progress` | No progress line on stderr. |
|
|
153
|
-
|
|
154
|
-
### The report
|
|
155
|
-
|
|
156
|
-
`repo-cleaner [target...]` lists each row with its verdict, why, the risks it
|
|
157
|
-
carries, and the command that would delete it.
|
|
158
|
-
|
|
159
|
-
| Option | Meaning |
|
|
160
|
-
| --- | --- |
|
|
161
|
-
| `--all` | Also show `keep` rows. By default only `delete`, `review` and `blocked` rows are listed. Only with `--format text`. |
|
|
162
|
-
| `--format text` | The report. The default. |
|
|
163
|
-
| `--format summary` | Counts per repository: total, merged, delete, prune, review, blocked, keep. |
|
|
164
|
-
| `--format commands` | Only the commands of `delete` rows that carry no risk, ready to copy. |
|
|
165
|
-
| `--format json` | Everything, evidence included, for scripts. |
|
|
166
|
-
|
|
167
|
-
```console
|
|
168
|
-
$ repo-cleaner --format summary --remote
|
|
169
|
-
/Users/me/work/api (acme/api, default main, origin)
|
|
170
|
-
total merged delete prune review blocked keep
|
|
171
|
-
local branches 12 8 6 0 1 0 5
|
|
172
|
-
worktrees 4 3 1 1 0 1 1
|
|
173
|
-
remote branches 40 31 30 0 6 0 4
|
|
174
|
-
|
|
175
|
-
37 to delete, 1 to prune, 7 to review, 1 blocked, across 1 repository.
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
`prune` counts worktree rows whose directory is gone, or is no longer a
|
|
179
|
-
checkout: deleting one drops the stale record, with `git worktree remove
|
|
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. |
|
|
211
|
-
|
|
212
|
-
```text
|
|
213
|
-
/Users/me/work/api
|
|
214
|
-
delete branch:fix/login-redirect
|
|
215
|
-
git update-ref -d refs/heads/fix/login-redirect 3f9c2e1d…
|
|
216
|
-
prune worktree:/Users/me/work/wt/old
|
|
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]
|
|
512
|
+
```sh
|
|
513
|
+
git fetch origin archive/api-local-2026-11-19
|
|
514
|
+
git log -1 --format=%B FETCH_HEAD # which parent is which
|
|
515
|
+
git worktree add ../restored FETCH_HEAD^2 # parent 2, a snapshot or a tip
|
|
516
|
+
git branch spike/cache FETCH_HEAD^3 # or keep a parent as a branch
|
|
224
517
|
```
|
|
225
518
|
|
|
226
|
-
|
|
227
|
-
|
|
519
|
+
The archive commit needs a git identity; without one configured, it is
|
|
520
|
+
written as `repo-cleaner`. Pruning old archive branches is not done here.
|
|
228
521
|
|
|
229
522
|
### Pick and spare
|
|
230
523
|
|
|
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.
|
|
524
|
+
**`--pick <row>`** means "also run this row". `clean` deletes the rows judged
|
|
525
|
+
`delete`; a `review` row, or a `keep` row with an action (a branch with an
|
|
526
|
+
open pull request), is deleted only when it is picked, so a borderline row
|
|
527
|
+
never goes as part of a batch. To leave rows out, spare them. The library's
|
|
528
|
+
`select` takes an exact list of rows instead, for a checklist or a host that
|
|
529
|
+
chose the rows itself.
|
|
239
530
|
|
|
240
531
|
Picking does not approve anything: a picked row that carries a risk still
|
|
241
532
|
needs `--allow` for it. A `blocked` row, or a `keep` row with no action, is
|
|
242
533
|
skipped and shown with the reason.
|
|
243
534
|
|
|
244
535
|
**`--spare <row>`** means "leave this row alone, and make sure it is what I
|
|
245
|
-
saw".
|
|
536
|
+
saw". A bare name (`--spare staging`) is that branch everywhere: its
|
|
537
|
+
worktree, its local branch, and its remote branch on every remote; in a
|
|
538
|
+
repository without it, nothing. A glob (`--spare 'release/*'`, `--spare
|
|
539
|
+
'remote:origin/tmp-*'`) leaves every row it matches alone, by name, a remote
|
|
540
|
+
branch also by its name without the remote, and a worktree by the branch it
|
|
541
|
+
has out; `*` stays within a `/`, `**` does not. A glob that matches nothing
|
|
542
|
+
is no error. The usual case: delete a merged worktree and its local branch, but keep
|
|
246
543
|
the branch on the remote as a backup.
|
|
247
544
|
|
|
248
545
|
- A spared row is not deleted, even if it is judged `delete`.
|
|
249
|
-
- A
|
|
546
|
+
- A remote branch spared by its full name (`remote:origin/x` or `origin/x`),
|
|
547
|
+
not by a bare branch name or a glob, is still checked. If it is gone or its tip moved
|
|
250
548
|
since the plan, the run stops before deleting anything: you spared it for
|
|
251
549
|
what it held, so if that changed, the rest of the plan rests on a wrong
|
|
252
550
|
assumption. The run's first step checks the tip again with `git ls-remote`,
|
|
@@ -286,6 +584,7 @@ you approve them by name with `--allow`:
|
|
|
286
584
|
| --- | --- |
|
|
287
585
|
| `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
586
|
| `discard-changes` | Uncommitted or untracked files in the worktree or any of its submodules. |
|
|
587
|
+
| `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
588
|
| `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
589
|
|
|
291
590
|
A worktree's submodules are part of it: one `--allow` on the worktree row
|
|
@@ -296,7 +595,7 @@ A branch whose worktree is judged `delete` is not held by it: the sweep judges
|
|
|
296
595
|
the branch on its own and records the worktree's path in `evidence.worktree`,
|
|
297
596
|
so one run removes the worktree and then deletes the branch. `clean` deletes
|
|
298
597
|
such a branch only when the same run removes its worktree, and drops it as
|
|
299
|
-
`held` otherwise. With `--
|
|
598
|
+
`held` otherwise. With `--branches` no worktree is swept, so the branch
|
|
300
599
|
stays held.
|
|
301
600
|
|
|
302
601
|
### Refused combinations
|
|
@@ -312,19 +611,29 @@ anything is swept; a row named two ways (a bare name and its id), and an
|
|
|
312
611
|
|
|
313
612
|
| Combination | Why |
|
|
314
613
|
| --- | --- |
|
|
614
|
+
| No phase named | The bare command explains the phases and runs nothing |
|
|
615
|
+
| A target that is no directory but a remote's name | `--remote upstream` with a space; write `--remote=upstream` |
|
|
616
|
+
| `--all` with `--remote=<name>` | `--all` is the default remote; write `--local --remote=<name>` |
|
|
315
617
|
| 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
|
-
|
|
|
618
|
+
| `--allow <risk>=<row>` for a spared row | Approves deleting something that will not be deleted |
|
|
619
|
+
| `-i` with `--pick`, or with `--plan -`; `-i` without a terminal | The checklist chooses the rows, on the terminal |
|
|
620
|
+
| A picked or spared row of a kind the scope leaves out | The row cannot be in the run |
|
|
318
621
|
| 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 |
|
|
622
|
+
| `--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 |
|
|
623
|
+
| `--plan` with targets, scope flags or sweep options | The plan already fixed what is swept |
|
|
321
624
|
| `--plan -` without `--yes` or `--dry-run` | stdin carries the plan, so nothing can ask |
|
|
322
625
|
| `--yes` with `--dry-run` | One deletes without asking, the other deletes nothing |
|
|
323
626
|
| `--receipt` with `--dry-run` | Nothing runs, so there is nothing to record |
|
|
324
|
-
| `--
|
|
325
|
-
| `--
|
|
326
|
-
|
|
|
327
|
-
|
|
|
627
|
+
| `--archive-exclude` without `--archive`, or `--allow discard-archived` without `--archive` | There is no archive for them to act on |
|
|
628
|
+
| `--fetch` with `--offline`, or with remote rows only | They contradict, or remote rows fetch anyway |
|
|
629
|
+
| `--offline` or `--provider` without remote rows | Nothing is fetched or looked up without them |
|
|
630
|
+
| 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 |
|
|
631
|
+
| `--all-rows` with any `--format` but `text` | `--all-rows` shows keep rows in the text report only |
|
|
632
|
+
|
|
633
|
+
A repository that cannot be judged as asked is an error row, and the rest are
|
|
634
|
+
still swept: a `--remote=<name>` or `--against` remote it does not have, a
|
|
635
|
+
bare `--remote` where several remotes leave no default, and an explicit
|
|
636
|
+
`--provider github` or `gitlab` over remotes on different kinds of host.
|
|
328
637
|
|
|
329
638
|
Refused after the sweep, before deleting, with exit 1:
|
|
330
639
|
|
|
@@ -343,12 +652,12 @@ Allowed, because nothing contradicts:
|
|
|
343
652
|
| `--allow <risk>` with `--allow <risk>=<row>` | The broader one covers it |
|
|
344
653
|
| `--allow` for a risk no row that runs carries | Runs; the preview lists it as `unused` |
|
|
345
654
|
| Picking a `blocked` or `keep` row | It is skipped and shown with the reason; the rest runs |
|
|
346
|
-
| `--
|
|
655
|
+
| A `--spare` glob that matches nothing | Nothing is spared by it |
|
|
347
656
|
|
|
348
657
|
### A remote with no checkout
|
|
349
658
|
|
|
350
659
|
```bash
|
|
351
|
-
repo-cleaner git@github.com:acme/api.git
|
|
660
|
+
repo-cleaner status git@github.com:acme/api.git
|
|
352
661
|
repo-cleaner clean git@github.com:acme/api.git
|
|
353
662
|
```
|
|
354
663
|
|
|
@@ -408,6 +717,18 @@ tracks a branch on a remote, other than the default branch (a branch made
|
|
|
408
717
|
with `--track` from `main` or `origin/main` does not count). With either, the worktree
|
|
409
718
|
is `delete`; with neither (`null`) it stays `review`.
|
|
410
719
|
|
|
720
|
+
A clean worktree whose HEAD is on a branch of the fetched remote is also
|
|
721
|
+
`delete`, whatever its PR state short of an open one (which keeps it), because the remote holds every commit. The
|
|
722
|
+
sweep must have fetched that remote (it is in scope, or `--fetch`, without
|
|
723
|
+
`--offline`): a local sweep's remote-tracking refs may name branches the remote
|
|
724
|
+
has deleted, so there the row keeps its verdict and a note says `--fetch` would
|
|
725
|
+
check. Every remote the sweep fetched counts. The default branch
|
|
726
|
+
does not count, the branch needs the same sign of use as above, and a dirty
|
|
727
|
+
worktree or one with submodule work is judged as before. `evidence.recoverableFrom`
|
|
728
|
+
lists the remote branches (`origin/topic`) and is part of the plan's
|
|
729
|
+
fingerprint. If a run also deletes every branch in that list, the worktree
|
|
730
|
+
needs `--allow abandon-unmerged`, since the run would remove the last copy.
|
|
731
|
+
|
|
411
732
|
Some worktrees are held back whatever their branch says and whatever is
|
|
412
733
|
allowed. Each lands in `row.blockers`, the row's verdict is `blocked`, and it
|
|
413
734
|
carries no command and no action:
|
|
@@ -541,11 +862,21 @@ reason, so a free-form reason such as `keep, build running` always blocks.
|
|
|
541
862
|
receipt records the `unlock-worktree` step.
|
|
542
863
|
- The owner is alive, or cannot be ruled out: `locked-worktree`.
|
|
543
864
|
- A lock writes `pid <N>` and, to guard against pid reuse, `start <time>`. The
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
865
|
+
start is read by [`@osdlc/file-lock`](../file-lock/README.md)'s
|
|
866
|
+
`sameProcess`, which takes:
|
|
867
|
+
- its `processIdentity`, the most reliable form: on Linux
|
|
868
|
+
`linux:<boot id>:<start ticks>`, checked against `/proc`, which neither a
|
|
869
|
+
clock change nor a time zone moves; elsewhere `start:<ms>`;
|
|
870
|
+
- a full ISO-8601 timestamp with a time of day and a zone
|
|
871
|
+
(`2026-10-25T18:22:19Z`; one with no zone is not accepted), epoch seconds
|
|
872
|
+
(9-10 digits) or epoch milliseconds (12-13 digits);
|
|
873
|
+
- the `ps -o lstart` form (`Sat Oct 25 18:22:19 2026`), which matches when it
|
|
874
|
+
is the real start in some time zone, since the writer's zone is unknown.
|
|
875
|
+
|
|
876
|
+
A pid is reused only after its owner exits, so only a live pid whose process
|
|
877
|
+
started more than two seconds after the recorded time is a reused pid and
|
|
878
|
+
counts as dead. A recorded time later than the start, such as when the
|
|
879
|
+
owner took the lock, still names the owner. Anything else, a date alone, a
|
|
549
880
|
short number or a partial date, cannot rule the owner out and the lock stays
|
|
550
881
|
a blocker.
|
|
551
882
|
- Only `ps` exiting 1 with no output and no error text means "no such pid".
|
|
@@ -556,7 +887,7 @@ reason, so a free-form reason such as `keep, build running` always blocks.
|
|
|
556
887
|
- Before the unlock and again before the remove, `clean` asks again, and reads
|
|
557
888
|
the process table afresh. If the owner is alive by then, or a process other
|
|
558
889
|
than an idle shell works in the directory, or the table cannot be read, the
|
|
559
|
-
step fails and the
|
|
890
|
+
step fails, and the steps that depend on it are skipped. A row dropped at the re-sweep touches nothing;
|
|
560
891
|
a step that fails at the unlock leaves the lock in place. `stale_lock` is part
|
|
561
892
|
of a worktree row's fingerprint, so a lock taken after the plan was written
|
|
562
893
|
drops the row too.
|
|
@@ -573,7 +904,10 @@ Both questions go to a `ProcessProbe` (`alive(pid, startedAt?)` and
|
|
|
573
904
|
`holders(path, { fresh? })`), passed as `probe` in the options of `sweep`,
|
|
574
905
|
`check` and `run`. The default, `defaultProcessProbe()`, runs
|
|
575
906
|
`ps -o lstart=`, `ps -A -o pid=,ppid=` and `lsof -d cwd` through
|
|
576
|
-
`@osdlc/command-seam`, and needs `ps` and `lsof` on `PATH`.
|
|
907
|
+
`@osdlc/command-seam`, and needs `ps` and `lsof` on `PATH`. `alive` first asks
|
|
908
|
+
`process.kill(pid, 0)`, so a gone pid costs no `ps`, and runs `ps` under
|
|
909
|
+
`TZ=UTC` and `LC_ALL=C` so the start time is one instant (a DST fall-back
|
|
910
|
+
cannot shift it). It reads the
|
|
577
911
|
process table once per probe and reuses it for every worktree: `sweep` makes
|
|
578
912
|
one probe per repository, and `run` uses one probe for its re-sweep and
|
|
579
913
|
reads the table afresh for each pre-unlock and pre-remove check. Where the
|
|
@@ -616,7 +950,7 @@ read. In 0.18 and earlier the repository came back as an error, and none of
|
|
|
616
950
|
it was judged:
|
|
617
951
|
|
|
618
952
|
```console
|
|
619
|
-
$ repo-cleaner --
|
|
953
|
+
$ repo-cleaner status --all --offline
|
|
620
954
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
621
955
|
error: GitHub has no such pull request, issue or repository, or you cannot see it.
|
|
622
956
|
|
|
@@ -626,7 +960,7 @@ $ repo-cleaner --remote --offline
|
|
|
626
960
|
Now the merged branch is still found, and the note says what was missing:
|
|
627
961
|
|
|
628
962
|
```console
|
|
629
|
-
$ repo-cleaner --
|
|
963
|
+
$ repo-cleaner status --all --offline
|
|
630
964
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
631
965
|
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
966
|
branch feat/login delete fully merged into origin/main
|
|
@@ -671,7 +1005,7 @@ The same happens when `gh` is not installed or not signed in. Nothing was
|
|
|
671
1005
|
asked, so nothing can rule out an open pull request:
|
|
672
1006
|
|
|
673
1007
|
```console
|
|
674
|
-
$ repo-cleaner --
|
|
1008
|
+
$ repo-cleaner status --all --offline
|
|
675
1009
|
~/work/app (acme/app, default main, origin, not fetched)
|
|
676
1010
|
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
1011
|
branch feat/login delete fully merged into origin/main
|
|
@@ -694,13 +1028,13 @@ no longer exists. In 0.18 and earlier it still called `git ls-remote`, and a
|
|
|
694
1028
|
remote that could not be read failed the whole repository:
|
|
695
1029
|
|
|
696
1030
|
```console
|
|
697
|
-
$ repo-cleaner --remote --offline --provider none
|
|
1031
|
+
$ repo-cleaner --remote --offline --provider none # 0.18 and earlier
|
|
698
1032
|
~/work/api (default main, origin, not fetched)
|
|
699
1033
|
error: git ls-remote: The remote '/srv/git/api.git' does not exist or is not a git repository. …
|
|
700
1034
|
```
|
|
701
1035
|
|
|
702
1036
|
```console
|
|
703
|
-
$ repo-cleaner --
|
|
1037
|
+
$ repo-cleaner status --all --offline --provider none # now
|
|
704
1038
|
~/work/api (default main, origin, not fetched)
|
|
705
1039
|
branch feat/login delete fully merged into origin/main
|
|
706
1040
|
git update-ref -d refs/heads/feat/login 255acd56…
|
|
@@ -722,7 +1056,7 @@ branch the remote no longer has is skipped as gone, and one whose tip moved
|
|
|
722
1056
|
is skipped too:
|
|
723
1057
|
|
|
724
1058
|
```console
|
|
725
|
-
$ repo-cleaner clean --remote --offline --provider none --
|
|
1059
|
+
$ repo-cleaner clean --remote --offline --provider none --yes
|
|
726
1060
|
skipped remote:origin/feat/search — gone (no longer in the sweep)
|
|
727
1061
|
ok remote:origin/feat/cart — git push … origin :refs/heads/feat/cart (ls-remote lists nothing)
|
|
728
1062
|
|
|
@@ -758,7 +1092,7 @@ The same information is on the result, for a host to show or act on:
|
|
|
758
1092
|
```ts
|
|
759
1093
|
import { sweep } from '@osdlc/repo-cleaner'
|
|
760
1094
|
|
|
761
|
-
const result = sweep(['.'], {
|
|
1095
|
+
const result = sweep(['.'], { remotes: [''], offline: true, provider: 'github' })
|
|
762
1096
|
for (const repo of result.repos) {
|
|
763
1097
|
if (repo.error !== null) {
|
|
764
1098
|
console.log(`${repo.path}: could not be swept: ${repo.error}`)
|
|
@@ -794,17 +1128,17 @@ The decision behind this is
|
|
|
794
1128
|
## Plan and clean
|
|
795
1129
|
|
|
796
1130
|
```bash
|
|
797
|
-
repo-cleaner clean #
|
|
798
|
-
repo-cleaner clean --
|
|
1131
|
+
repo-cleaner clean # look, show the steps, ask, delete
|
|
1132
|
+
repo-cleaner clean --worktrees --yes # no question
|
|
799
1133
|
repo-cleaner plan -o plan.json # save the plan to review or edit
|
|
800
1134
|
repo-cleaner clean --plan plan.json --pick branch:feat/x
|
|
801
1135
|
repo-cleaner plan | repo-cleaner clean --plan - --yes
|
|
802
1136
|
```
|
|
803
1137
|
|
|
804
1138
|
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
|
-
|
|
1139
|
+
and the sweep options it was made with. The rows judged `delete` run, and
|
|
1140
|
+
the rows picked; the blocked and structural rows are there so a pick of one
|
|
1141
|
+
is skipped with its reason. `clean`
|
|
808
1142
|
either sweeps and plans in memory, or reads a plan with `--plan`. A plan of an
|
|
809
1143
|
older version is refused, not translated: sweep again.
|
|
810
1144
|
|
|
@@ -819,15 +1153,44 @@ plan's sweep did, so it judges against the same, current default branch.
|
|
|
819
1153
|
|
|
820
1154
|
On yes it runs only the steps it showed: spared remote tips first, then
|
|
821
1155
|
worktrees, local branches and remote branches, in that order. Branch
|
|
822
|
-
deletes are compare-and-swap
|
|
823
|
-
|
|
1156
|
+
deletes are compare-and-swap and every step is verified.
|
|
1157
|
+
|
|
1158
|
+
A step that fails is marked `failed`, and the steps that depend on it are
|
|
1159
|
+
marked `skipped`, with the failed step named in the receipt's `error`. Every
|
|
1160
|
+
other step runs, so one worktree that cannot be removed no longer leaves the
|
|
1161
|
+
rest undone.
|
|
1162
|
+
|
|
1163
|
+
| Failed step | Skipped | Why |
|
|
1164
|
+
| --- | --- | --- |
|
|
1165
|
+
| `verify-remote` (a spared tip moved or is gone) | every later step: the run stops | the plan's premise no longer holds |
|
|
1166
|
+
| `unlock-worktree` | that row's `remove-worktree` or `prune-worktrees` | it is still locked |
|
|
1167
|
+
| `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 |
|
|
1168
|
+
| `delete-branch` | the same branch's `delete-remote` in the same repository | the remote copy may be the one the plan relied on |
|
|
1169
|
+
| any | nothing in another repository, and no unrelated row | independent |
|
|
1170
|
+
|
|
1171
|
+
A step skipped for a skipped step names the failed step at the root. The run
|
|
1172
|
+
still ends `failed` (exit `11`) when any step failed. Every run ends with what
|
|
1173
|
+
it did:
|
|
824
1174
|
|
|
825
1175
|
```text
|
|
826
1176
|
deleted: 1 worktree, 3 local branches, 2 remote branches, 1 stale worktree pruned
|
|
1177
|
+
freed: 1.3 GB (1 worktree)
|
|
827
1178
|
skipped 2, not deleted: 1 needs-pick (name with --pick), 1 duplicate
|
|
828
1179
|
status: complete
|
|
829
1180
|
```
|
|
830
1181
|
|
|
1182
|
+
A run with a failure adds a line such as `9 steps ran, 1 failed, 2 skipped`; a
|
|
1183
|
+
run stopped by a spared tip says how many rows did not run instead.
|
|
1184
|
+
|
|
1185
|
+
`freed` is the disk space of the worktrees the run removed, each read with
|
|
1186
|
+
`du -sk` just before its removal and kept on its `remove-worktree` step as
|
|
1187
|
+
`freedBytes` in the receipt. A failed removal frees nothing, and a pruned
|
|
1188
|
+
worktree's directory was already gone, so neither counts. A size `du` could
|
|
1189
|
+
not read (it failed, or ran past 60 s) is `freedBytes: null`, and the line
|
|
1190
|
+
says `freed: at least 4.2 GB (2 worktrees, 1 not measured)`. `--format json`
|
|
1191
|
+
carries the totals as `summary.freedBytes` and `summary.unmeasured`. A dry run
|
|
1192
|
+
measures nothing.
|
|
1193
|
+
|
|
831
1194
|
Two clones of one remote list the same remote branches; `clean` deletes each
|
|
832
1195
|
once and drops the other clone's row as `duplicate`, or as `spared` when the
|
|
833
1196
|
branch is spared through the other clone. Remotes are compared by the push URL
|
|
@@ -843,24 +1206,24 @@ that swept, or read its plan from stdin, writes a receipt only when
|
|
|
843
1206
|
|
|
844
1207
|
| Code | Meaning |
|
|
845
1208
|
| --- | --- |
|
|
846
|
-
| `0` |
|
|
1209
|
+
| `0` | Looked or saved; or `clean` ran, was declined, or had nothing to do |
|
|
847
1210
|
| `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` |
|
|
1211
|
+
| `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
1212
|
| `10` | Nothing to sweep: no target named a repository |
|
|
850
|
-
| `11` | `clean`
|
|
1213
|
+
| `11` | `clean` had a failed step; the receipt says which, and which steps it skipped. A failed spared-tip check stops the run |
|
|
851
1214
|
|
|
852
1215
|
## As a library
|
|
853
1216
|
|
|
854
1217
|
```ts
|
|
855
1218
|
import { check, plan, render, run, sweep } from '@osdlc/repo-cleaner'
|
|
856
1219
|
|
|
857
|
-
const result = sweep(['/Users/me/work/api'], {
|
|
1220
|
+
const result = sweep(['/Users/me/work/api'], { remotes: [''] })
|
|
858
1221
|
for (const row of result.repos[0]?.rows ?? []) {
|
|
859
1222
|
console.log(row.id, row.verdict, row.why, row.risks)
|
|
860
1223
|
}
|
|
861
1224
|
|
|
862
1225
|
const preview = check(plan(result), {
|
|
863
|
-
|
|
1226
|
+
select: ['branch:spike/cache'],
|
|
864
1227
|
allow: [{ risk: 'abandon-unmerged', row: 'branch:spike/cache' }],
|
|
865
1228
|
})
|
|
866
1229
|
process.stdout.write(render.preview(preview))
|
|
@@ -869,10 +1232,10 @@ const receipt = run(preview)
|
|
|
869
1232
|
|
|
870
1233
|
| Export | What it does |
|
|
871
1234
|
| --- | --- |
|
|
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` |
|
|
1235
|
+
| `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
1236
|
| `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 |
|
|
1237
|
+
| `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 |
|
|
1238
|
+
| `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
1239
|
| `inspectWorktree(path, opts?)` | One worktree judged as a sweep judges it, submodules included |
|
|
877
1240
|
| `readPlan`, `writePlan` | Plans on disk |
|
|
878
1241
|
| `render` | The command line's formats: `text`, `json`, `summary`, `commands`, `preview`, `receipt` |
|
|
@@ -935,8 +1298,25 @@ branch.
|
|
|
935
1298
|
|
|
936
1299
|
| Provider | CLI | Listing |
|
|
937
1300
|
| --- | --- | --- |
|
|
938
|
-
| `github` | `gh` | `gh pr list --
|
|
939
|
-
| `gitlab` | `glab` | `glab api projects/<path>/merge_requests
|
|
1301
|
+
| `github` | `gh` | `gh pr list --repo <host>/<project>`: every open PR (up to 1000), then the newest 300 of any state |
|
|
1302
|
+
| `gitlab` | `glab` | `glab api projects/<path>/merge_requests`, 100 a page: every opened MR (up to 1000), then the newest 300 of any state |
|
|
1303
|
+
|
|
1304
|
+
Open PRs are what gate a delete, so they are read on their own and an old open
|
|
1305
|
+
one is found however many newer PRs there are. Merged and closed PRs past the
|
|
1306
|
+
newest 300 are not read; they only prove that work landed, so a branch whose
|
|
1307
|
+
merged PR is that old falls back to ancestry or a patch match. A listing that
|
|
1308
|
+
stops at the open-PR cap is incomplete.
|
|
1309
|
+
|
|
1310
|
+
The PRs a fork opens live in its parent, so for a fork on GitHub the parent's
|
|
1311
|
+
PRs whose head repository is the fork are listed too, under the same caps, and
|
|
1312
|
+
count for the fork's branches. A parent listing that fails or stops at a cap
|
|
1313
|
+
leaves the listing incomplete, as does a fork whose parent cannot be named.
|
|
1314
|
+
For an incomplete listing the repository carries a note, and a remote branch
|
|
1315
|
+
with no PR found needs `confirm-open-pr` to delete, as after a failed listing.
|
|
1316
|
+
|
|
1317
|
+
The GitHub provider names the repository the sweep judges (`--repo`), not the
|
|
1318
|
+
one `gh` would pick from the checkout's remotes, which prefers `upstream` over
|
|
1319
|
+
`origin`.
|
|
940
1320
|
|
|
941
1321
|
With `--remote`, `--provider auto` (the default) reads the remote's host: a
|
|
942
1322
|
remote that names no host (a local path or `file://`) gets no provider, since
|