@feigi/fleet-ctl 3.24.18 → 3.24.19
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/package.json +1 -1
- package/scripts/reap.sh +212 -216
package/package.json
CHANGED
package/scripts/reap.sh
CHANGED
|
@@ -29,12 +29,12 @@ set -eu
|
|
|
29
29
|
# `tr` exits 1 on a byte that is not valid UTF-8, `paste` truncates its whole
|
|
30
30
|
# output at it and still exits 0, and `grep` does one of TWO things: it drops
|
|
31
31
|
# the offending line at rc 0/1, or it gives up on the scan and exits 2. Only
|
|
32
|
-
# the first half was ever written down here, which is why the second read
|
|
33
|
-
# clean no-match at all four call sites
|
|
34
|
-
#
|
|
32
|
+
# the first half was ever written down here, which is why the second once read
|
|
33
|
+
# as a clean no-match at all four call sites — the reason `grep_probe` below
|
|
34
|
+
# takes grep's own status apart from grep's verdict.
|
|
35
35
|
#
|
|
36
|
-
# `awk` is NOT immune, and
|
|
37
|
-
# earlier claim here false: it is byte-identical only when every rule matches
|
|
36
|
+
# `awk` is NOT immune, and a fixture in this script's own test suite measured
|
|
37
|
+
# the earlier claim here false: it is byte-identical only when every rule matches
|
|
38
38
|
# at an ANCHOR before the bad byte, never needing to convert it. A rule that
|
|
39
39
|
# must SCAN PAST the byte to decide — here, the `/^branch /` match against a
|
|
40
40
|
# worktree's raw, unquoted registry path, one SIBLING entry away from the
|
|
@@ -42,28 +42,27 @@ set -eu
|
|
|
42
42
|
# at rc 2 (`towc: multibyte conversion failure`), and this script runs under
|
|
43
43
|
# `set -eu`, so that death TERMINATES the whole sweep rather than merely
|
|
44
44
|
# mis-scoring one record. gawk and mawk (Linux CI) tolerate the same byte and
|
|
45
|
-
# answer rc 0, which is why this is a macOS-only ceiling, not a portable fix
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
# answer.
|
|
45
|
+
# answer rc 0, which is why this is a macOS-only ceiling, not a portable fix.
|
|
46
|
+
# Such a byte reaches us from a fetched tree even where the local filesystem
|
|
47
|
+
# refuses to hold the name. Leaving this ambient in no-undo-audit.sh was
|
|
48
|
+
# measured to cost a truncated list reported as a clean, confident answer.
|
|
50
49
|
#
|
|
51
50
|
# Safe as a global: nothing in this script sorts, folds case, or uses a `[a-z]`
|
|
52
51
|
# range or a POSIX class, so collation and case-folding — the two things
|
|
53
52
|
# `LC_ALL=C` otherwise changes — have nothing here to act on. "Nothing" is an
|
|
54
|
-
# inventory, not a hope: locale-pin
|
|
53
|
+
# inventory, not a hope: the suite's locale-pin prose test enforces it, because
|
|
55
54
|
# this sentence shipped false in no-undo-audit.sh and a `sort` added below
|
|
56
55
|
# would otherwise leave every test in this suite green.
|
|
57
56
|
export LC_ALL=C
|
|
58
57
|
|
|
59
58
|
# Below the locale pin, not above it with `set -eu`: `unset` touches no
|
|
60
|
-
# byte-sensitive tool, but locale-pin
|
|
59
|
+
# byte-sensitive tool, but the locale-pin prose test treats ANY line here that
|
|
61
60
|
# is not a comment, a blank, or `set -[eux]+` as work the pin must sit above,
|
|
62
61
|
# and refuses on principle rather than on this line's own behaviour. Same
|
|
63
62
|
# placement, same reason, as release-ticket.sh's copy.
|
|
64
63
|
#
|
|
65
64
|
# This is the script the class costs the most, and both halves are measured on
|
|
66
|
-
# it
|
|
65
|
+
# it.
|
|
67
66
|
#
|
|
68
67
|
# GIT_DIR: nothing in the sweeps carries a `-C`. An ambient one therefore does
|
|
69
68
|
# not merely misreport — it MOVES THE DELETIONS. Measured, `--apply` run from
|
|
@@ -86,8 +85,8 @@ unset GIT_DIR GIT_WORK_TREE
|
|
|
86
85
|
NAME=reap
|
|
87
86
|
die() { printf '%s: %s\n' "$NAME" "$1" >&2; exit 2; }
|
|
88
87
|
|
|
89
|
-
# The escaping helpers
|
|
90
|
-
#
|
|
88
|
+
# The escaping helpers. json.sh's header holds the sourcing contract and the
|
|
89
|
+
# measurements behind it. This script defines no exit 1 at all, so a
|
|
91
90
|
# bare 1 out of it is a code its caller has no reading for. Placed here, above
|
|
92
91
|
# the fetch, so a missing library refuses before anything is deleted rather than
|
|
93
92
|
# partway through.
|
|
@@ -97,7 +96,7 @@ json_lib="$(dirname "$0")/json.sh"
|
|
|
97
96
|
# shellcheck source=json.sh
|
|
98
97
|
. "$json_lib" || die "$json_lib failed to load"
|
|
99
98
|
|
|
100
|
-
# The bounded, prompt-suppressed git transport
|
|
99
|
+
# The bounded, prompt-suppressed git transport. The fetch
|
|
101
100
|
# below is unattended: with no bound it can prompt for a credential or a host
|
|
102
101
|
# key, or stall on a transport that connects and then goes quiet, and either
|
|
103
102
|
# holds a fleet slot until something outside kills it. net.sh's header holds the
|
|
@@ -109,7 +108,7 @@ net_lib="$(dirname "$0")/net.sh"
|
|
|
109
108
|
# shellcheck source=net.sh
|
|
110
109
|
. "$net_lib" || die "$net_lib failed to load"
|
|
111
110
|
|
|
112
|
-
# The worktree readers
|
|
111
|
+
# The worktree readers. worktree.sh's header holds the sourcing
|
|
113
112
|
# contract and the measurements behind it, and json.sh's holds the `[ -r ]`
|
|
114
113
|
# reasoning all three guards share. Sourced below json.sh so a lone copy of this
|
|
115
114
|
# script still blames json.sh, the name its missing-library test pins, and above
|
|
@@ -125,7 +124,7 @@ wt_lib="$(dirname "$0")/worktree.sh"
|
|
|
125
124
|
# passed whatever it said. Measured on the pre-fix script over identical
|
|
126
125
|
# fixtures, `reap.sh --aply` and a bare `reap.sh` both exited 0 with
|
|
127
126
|
# byte-identical stdout and stderr — same payload, same banner, same per-branch
|
|
128
|
-
# lines — so nothing in the run said the flag had not been understood
|
|
127
|
+
# lines — so nothing in the run said the flag had not been understood.
|
|
129
128
|
# Both refusals sit above the fetch, so a rejected invocation reads nothing and
|
|
130
129
|
# deletes nothing.
|
|
131
130
|
apply=false
|
|
@@ -148,12 +147,12 @@ base=${BASE_REF:-origin/main}
|
|
|
148
147
|
# and nothing at the delete refuses it: the compare-and-swap there refuses
|
|
149
148
|
# only a ref that moved, and the holder check only a branch a worktree holds.
|
|
150
149
|
#
|
|
151
|
-
# It is also what makes the qualification below sound rather than a guess.
|
|
152
|
-
# recorded
|
|
153
|
-
# a tag, a sha or a local branch, leaving no prefix that is always
|
|
154
|
-
# restricting the input first removes that objection instead of
|
|
155
|
-
# it. Placed with the argument guards above the fetch, so a
|
|
156
|
-
# reads nothing and deletes nothing.
|
|
150
|
+
# It is also what makes the qualification below sound rather than a guess.
|
|
151
|
+
# Qualifying was once recorded as unavailable here precisely because BASE_REF
|
|
152
|
+
# might name a tag, a sha or a local branch, leaving no prefix that is always
|
|
153
|
+
# correct; restricting the input first removes that objection instead of
|
|
154
|
+
# working around it. Placed with the argument guards above the fetch, so a
|
|
155
|
+
# rejected invocation reads nothing and deletes nothing.
|
|
157
156
|
case "$base" in
|
|
158
157
|
origin/*|refs/remotes/*) ;;
|
|
159
158
|
*) die "BASE_REF must be a remote-tracking ref, got '$base'";;
|
|
@@ -187,8 +186,8 @@ esac
|
|
|
187
186
|
# DEFAULT, so no accept-list catches it; and `git rev-parse --verify "$base"`
|
|
188
187
|
# exits 0 whichever ref it picked — git's own
|
|
189
188
|
# `warning: refname 'origin/main' is ambiguous.` reaches stderr, where this
|
|
190
|
-
# script reads nothing and an unattended run has no one to read it.
|
|
191
|
-
#
|
|
189
|
+
# script reads nothing and an unattended run has no one to read it. The fix
|
|
190
|
+
# pattern is the one proven in release-ticket.sh:264.
|
|
192
191
|
#
|
|
193
192
|
# refs/remotes/ leaves nothing to disambiguate, and the accept-list above
|
|
194
193
|
# already establishes $base is spelled for that namespace. $base itself is
|
|
@@ -215,7 +214,7 @@ git rev-parse --git-dir >/dev/null 2>&1 || die "not inside a git repository"
|
|
|
215
214
|
# below refuse this one path and report it as a `kept` finding, which is the
|
|
216
215
|
# remedy an operator can act on — it is one `cd` away. Chdir-ing somewhere
|
|
217
216
|
# durable at the foot of the file would cover the prune only, and the prune is
|
|
218
|
-
# the LAST call that needs a cwd, not the only one.
|
|
217
|
+
# the LAST call that needs a cwd, not the only one.
|
|
219
218
|
#
|
|
220
219
|
# `--show-toplevel`, never `pwd`: this script may be invoked from a
|
|
221
220
|
# subdirectory, and that answers the worktree ROOT — the directory
|
|
@@ -223,13 +222,13 @@ git rev-parse --git-dir >/dev/null 2>&1 || die "not inside a git repository"
|
|
|
223
222
|
# the listing echoes the path recorded at `worktree add` time, which a parent
|
|
224
223
|
# turned symlink since leaves non-canonical, and which `core.precomposeunicode`
|
|
225
224
|
# prints precomposed for a worktree whose on-disk name is NFD while git's own
|
|
226
|
-
# answer is the NFD bytes (measured, git 2.50.1, Apple Git-155
|
|
225
|
+
# answer is the NFD bytes (measured, git 2.50.1, Apple Git-155). So
|
|
227
226
|
# `holds_cwd` below matches on the directory, not only the string.
|
|
228
227
|
#
|
|
229
228
|
# `2>/dev/null` and never `2>&1`, for the reason the in-progress guard below
|
|
230
229
|
# records at its own `rev-parse`: this capture is used as a PATH, not as
|
|
231
230
|
# message text, and a `~/.gitconfig` with a key outside any section makes every
|
|
232
|
-
# git command print `error: key does not contain a section: …` AT EXIT 0
|
|
231
|
+
# git command print `error: key does not contain a section: …` AT EXIT 0
|
|
233
232
|
# — folded in, that line would arrive glued in front of the path and match no
|
|
234
233
|
# worktree ever again.
|
|
235
234
|
#
|
|
@@ -242,16 +241,16 @@ git rev-parse --git-dir >/dev/null 2>&1 || die "not inside a git repository"
|
|
|
242
241
|
# enumeration below skips a bare entry outright.
|
|
243
242
|
#
|
|
244
243
|
# Any OTHER failure of this probe is NOT that answer and must not be folded
|
|
245
|
-
# into it. Doing so silently disables both cwd-delete guards below
|
|
246
|
-
#
|
|
247
|
-
#
|
|
248
|
-
# naming the probe that broke, so an operator chasing a
|
|
249
|
-
# prune refusal, a branch delete dying on
|
|
244
|
+
# into it. Doing so silently disables both cwd-delete guards below — every
|
|
245
|
+
# removal proceeds as though this run were standing in no worktree at all,
|
|
246
|
+
# reproducing the very cwd deletion those guards exist to stop. Fail closed
|
|
247
|
+
# instead: die, naming the probe that broke, so an operator chasing a
|
|
248
|
+
# downstream failure (a prune refusal, a branch delete dying on
|
|
250
249
|
# "Unable to read current working directory") lands on the real cause here
|
|
251
250
|
# rather than the symptom.
|
|
252
251
|
#
|
|
253
252
|
# The success path keeps `2>/dev/null`, never `2>&1`: folding stderr in would
|
|
254
|
-
# glue the
|
|
253
|
+
# glue the stray-gitconfig warning onto the path on a plain SUCCESS too.
|
|
255
254
|
# Stderr is only re-captured, on a second call, once the first has already
|
|
256
255
|
# failed — the classification never touches the value the guards compare
|
|
257
256
|
# against. `self_wt_rc=…` (not `|| self_wt=`) keeps the check off `set -e`.
|
|
@@ -270,13 +269,13 @@ if [ "$self_wt_rc" -ne 0 ]; then
|
|
|
270
269
|
fi
|
|
271
270
|
|
|
272
271
|
# True when removing worktree `$1` would delete this run's cwd: `$self_wt` is
|
|
273
|
-
# `$1` or lies anywhere beneath it (
|
|
272
|
+
# `$1` or lies anywhere beneath it (a nested worktree). Asked of the
|
|
274
273
|
# DIRECTORY, not the string: `-ef` (same device and inode) of `$self_wt` and of
|
|
275
274
|
# each of its parents in turn. The byte-boundary prefix match this replaces
|
|
276
275
|
# missed the same directory spelled two ways — the symlinked parent and the NFD
|
|
277
276
|
# name the header above records share no prefix with git's own answer — and
|
|
278
|
-
# `--apply` deleted the cwd it was standing in
|
|
279
|
-
#
|
|
277
|
+
# `--apply` deleted the cwd it was standing in (measured). An empty `$self_wt`
|
|
278
|
+
# (no worktree) names no directory, so it matches
|
|
280
279
|
# nothing; the walk ends when no `/` is left to strip.
|
|
281
280
|
#
|
|
282
281
|
# `elif` on `$?`, same refusing direction `wt_linkage_why` states for its own
|
|
@@ -285,7 +284,7 @@ fi
|
|
|
285
284
|
# unreached today, not impossible — and unlike `wt_linkage_why`, nothing
|
|
286
285
|
# downstream of THIS guard re-checks the directory it protects. Reading that
|
|
287
286
|
# rc as a plain "not this one" would silently disable both cwd-delete guards
|
|
288
|
-
# exactly the way an unrecognised `self_wt` failure would (
|
|
287
|
+
# exactly the way an unrecognised `self_wt` failure would (the probe's note
|
|
289
288
|
# above), just one layer further in.
|
|
290
289
|
holds_cwd() {
|
|
291
290
|
hc_d=$self_wt
|
|
@@ -317,7 +316,7 @@ fi
|
|
|
317
316
|
# measurement below uses, so it is the one whose existence has to be
|
|
318
317
|
# established — and asking about it is also what turns a BASE_REF that only
|
|
319
318
|
# resolves as a TAG into a refusal here rather than a merge probe answered by
|
|
320
|
-
# the wrong commit
|
|
319
|
+
# the wrong commit. The message names `$base`, the spelling the caller
|
|
321
320
|
# passed and the only one it can act on.
|
|
322
321
|
git rev-parse --verify "$base_rev" >/dev/null || die "$base does not resolve"
|
|
323
322
|
[ "$apply" = true ] || echo "$NAME: DRY RUN — nothing will be deleted. Pass --apply to act." >&2
|
|
@@ -329,13 +328,13 @@ warnings=""
|
|
|
329
328
|
# not. One meaning, so the key needs no qualifier: the sweep below reaps
|
|
330
329
|
# worktrees no `reaped` branch names, and a payload that recorded only those
|
|
331
330
|
# would leave a reader guessing whether the branch sweep's removals were absent
|
|
332
|
-
# because none happened or because nothing reports them
|
|
331
|
+
# because none happened or because nothing reports them.
|
|
333
332
|
removed=""
|
|
334
333
|
# `jstr`'s output wrapped in the quotes JSON needs, or the literal `null` where
|
|
335
334
|
# it could not render. `die` is the wrong answer at both call sites below: by
|
|
336
335
|
# the time either accumulator is written this script may already have deleted
|
|
337
336
|
# branches, and the payload printed at the end is the caller's only record of
|
|
338
|
-
# that — the same reason
|
|
337
|
+
# that — the same reason the printf runs ahead of the prune. Exiting here
|
|
339
338
|
# would destroy the record of work that already happened. So an unrenderable
|
|
340
339
|
# field becomes `null` and the run still reports what it did, the ruling
|
|
341
340
|
# inflight.sh's `add_evidence` records for the same shape.
|
|
@@ -351,12 +350,12 @@ removed=""
|
|
|
351
350
|
# directly and never routes through `keep` at all. The branch name is the
|
|
352
351
|
# demonstrated trigger — `git branch 'has"quote'` is a legal refname — and raw
|
|
353
352
|
# it emitted a payload no parser accepts at exit 0, while the branch was
|
|
354
|
-
# correctly kept
|
|
353
|
+
# correctly kept. The stderr lines stay raw: they are prose for an
|
|
355
354
|
# operator, not JSON.
|
|
356
355
|
#
|
|
357
|
-
# A sixth joined the five above
|
|
356
|
+
# A sixth joined the five above later: grep's own stderr, `$gq_err`,
|
|
358
357
|
# surfaced through `gp_why "$gq_err"` in `keep`'s message at the two cherry
|
|
359
|
-
# checks and the two registry re-reads
|
|
358
|
+
# checks and the two registry re-reads —
|
|
360
359
|
# arbitrary text on the same footing as `$cherry`, routed through the same
|
|
361
360
|
# jfield/jstr escaping the paragraph above already covers. Left out of the
|
|
362
361
|
# "eleven call sites" figure above, which still counts only the original
|
|
@@ -386,10 +385,10 @@ keep() {
|
|
|
386
385
|
|
|
387
386
|
# Runs `git "$@"`, and unlike a bare `$(git … 2>/dev/null)` this keeps git's
|
|
388
387
|
# stderr instead of discarding it — into $gp_err, never mixed into $gp_out,
|
|
389
|
-
# with git's own exit status returned by this function.
|
|
390
|
-
#
|
|
391
|
-
#
|
|
392
|
-
#
|
|
388
|
+
# with git's own exit status returned by this function. This file's worktree
|
|
389
|
+
# status probes used to throw stderr away, so a `fatal:` at rc 128 named no
|
|
390
|
+
# cause and a `warning:` at rc 0 (measured — a permission-denied ignored
|
|
391
|
+
# directory) reached nobody. The wrong fix is
|
|
393
392
|
# `2>&1`: each of these probes is followed by a `[ -n "$gp_out" ]` dirty test,
|
|
394
393
|
# which reads the captured text as content, so folding a warning in would make a
|
|
395
394
|
# clean worktree with ANY git warning on it read as dirty forever.
|
|
@@ -408,7 +407,7 @@ keep() {
|
|
|
408
407
|
# at, by two DIFFERENT rules for two DIFFERENT groups. Three call sites below
|
|
409
408
|
# read `status --porcelain` (`-uall`, or `-unormal --ignored`) and are safe
|
|
410
409
|
# because git quotes PATHS; a fourth, added after this comment was first
|
|
411
|
-
# written
|
|
410
|
+
# written, reads `for-each-ref --format='%(refname)
|
|
412
411
|
# %(upstream:track)'` and is safe for an unrelated reason — a REFNAME,
|
|
413
412
|
# unlike a path, can never contain the byte at all. Nothing in the body
|
|
414
413
|
# checks either invariant.
|
|
@@ -422,7 +421,7 @@ keep() {
|
|
|
422
421
|
# backslash-002 inside quotes, never the raw byte. This does NOT hang on
|
|
423
422
|
# `core.quotePath`, which only demotes bytes >= 0x80 out of "unusual";
|
|
424
423
|
# "git quotes unusual bytes" is therefore the wrong claim to rest on,
|
|
425
|
-
# since
|
|
424
|
+
# since that exact escape hatch was measured for the HIGH-BIT class (see
|
|
426
425
|
# derive-testcmd.sh). Zero raw 0x02 out of `--porcelain -uall` and out of
|
|
427
426
|
# `--porcelain --ignored`, under core.quotePath true AND false.
|
|
428
427
|
#
|
|
@@ -437,8 +436,8 @@ keep() {
|
|
|
437
436
|
# refs/heads/"$(printf 'a\002b')" HEAD` — `refusing to update ref with bad
|
|
438
437
|
# name`. `%(refname)` and `%(upstream:track)` can only ever answer with
|
|
439
438
|
# bytes that already survived `check-ref-format` on the way in, so a raw
|
|
440
|
-
# 0x02 can never reach either field to begin with. A fifth call site
|
|
441
|
-
#
|
|
439
|
+
# 0x02 can never reach either field to begin with. A fifth call site joins
|
|
440
|
+
# this ref group: `rev-parse --verify refs/heads/<b>`, where
|
|
442
441
|
# `<b>` is a name the `for-each-ref` call site produced. Its stdout is an
|
|
443
442
|
# object id in hex, and what it can put on stderr is git's own fixed prose
|
|
444
443
|
# around that same validated refname.
|
|
@@ -448,7 +447,7 @@ keep() {
|
|
|
448
447
|
# and nothing here catches a caller who drops it: a raw separator truncates
|
|
449
448
|
# $gp_out at that byte and concatenates the rest of the real output onto
|
|
450
449
|
# $gp_rc, which then reaches `return` as a non-numeric string (measured
|
|
451
|
-
# against a stub git
|
|
450
|
+
# against a stub git). It is one flag away from the path
|
|
452
451
|
# group, not hypothetical — same git, same fixture: `status --porcelain
|
|
453
452
|
# -uall -z` carries the raw 0x02 straight through, `-z` being the
|
|
454
453
|
# machine-readable form that drops the quoting, and so does any command
|
|
@@ -458,7 +457,7 @@ keep() {
|
|
|
458
457
|
# warning is really aimed at the path group and at any THIRD kind of call
|
|
459
458
|
# site a future caller might add.
|
|
460
459
|
#
|
|
461
|
-
# Left unguarded anyway, deliberately
|
|
460
|
+
# Left unguarded anyway, deliberately: every call site is shaped
|
|
462
461
|
# `if ! git_probe …; then keep …`, so a garbled $gp_rc can never come back 0
|
|
463
462
|
# and so can never turn a KEEP into a REAP. For a script whose only costly
|
|
464
463
|
# failure is deleting something it should have kept, that is the direction
|
|
@@ -470,7 +469,7 @@ keep() {
|
|
|
470
469
|
# `gp_o=$(...); gp_rc=$?`: under `set -e` a bare failing assignment aborts the
|
|
471
470
|
# subshell before `gp_rc=$?` or the printf below ever run, and `gp_raw` comes
|
|
472
471
|
# back empty — silently, at the one moment this function exists to not be
|
|
473
|
-
# silent (measured on this exact shape
|
|
472
|
+
# silent (measured on this exact shape).
|
|
474
473
|
gp_sep=$(printf '\002')
|
|
475
474
|
git_probe() {
|
|
476
475
|
gp_raw=$(
|
|
@@ -528,7 +527,7 @@ gp_cut_short() {
|
|
|
528
527
|
# own scanner's stderr into `$gq_err`, and both need these same two guards.
|
|
529
528
|
# Taken as an argument rather than by duplicating the stripper, so a fix to
|
|
530
529
|
# either guard cannot land in one copy and miss the other. Every git-side call
|
|
531
|
-
# site passes nothing and still reads `$gp_err`.
|
|
530
|
+
# site passes nothing and still reads `$gp_err`.
|
|
532
531
|
gp_why() {
|
|
533
532
|
gp_w=$(printf '%s' "${1-$gp_err}" | tr '\n' ' ')
|
|
534
533
|
while :; do
|
|
@@ -553,7 +552,7 @@ gp_why() {
|
|
|
553
552
|
# there reads clean over the work sitting in `$wt` — the dry run promised a
|
|
554
553
|
# removal `--apply` could not perform, `git worktree remove`'s own back-pointer
|
|
555
554
|
# and untracked-file checks being all that kept the work (measured on both
|
|
556
|
-
# shapes, both sweeps, git 2.50.1
|
|
555
|
+
# shapes, both sweeps, git 2.50.1). `--show-toplevel` names the tree git
|
|
557
556
|
# actually answers for, so it is compared against `$1`.
|
|
558
557
|
#
|
|
559
558
|
# Compared as a DIRECTORY (`-ef`, same device and inode), never as a string:
|
|
@@ -561,11 +560,11 @@ gp_why() {
|
|
|
561
560
|
# git's own resolved spelling, and the two legitimately differ for one and the
|
|
562
561
|
# same directory. A parent that was a plain directory at `worktree add` time
|
|
563
562
|
# and is a symlink now leaves the listed path non-canonical while git's answer
|
|
564
|
-
# is resolved (measured
|
|
563
|
+
# is resolved (measured). And a worktree whose name is Unicode
|
|
565
564
|
# NFD-composed (`cafe` + U+0301) is listed PRECOMPOSED by the
|
|
566
565
|
# `core.precomposeunicode` git writes into every new repo on macOS, while
|
|
567
566
|
# `--show-toplevel` answers the on-disk NFD bytes — visually identical,
|
|
568
|
-
# byte-different, one directory (measured, git 2.50.1, Apple Git-155
|
|
567
|
+
# byte-different, one directory (measured, git 2.50.1, Apple Git-155).
|
|
569
568
|
# `cd && pwd -P` canonicalises only the first: it echoes the spelling it was
|
|
570
569
|
# given, so a byte compare against it kept every healthy NFD worktree forever.
|
|
571
570
|
# `-ef` answers "same directory" for both and for any other spelling the
|
|
@@ -581,13 +580,13 @@ gp_why() {
|
|
|
581
580
|
# trailing newline, so a `core.worktree` naming a sibling directory called
|
|
582
581
|
# `<wt>` plus a newline byte — git accepts one as an ordinary path character —
|
|
583
582
|
# would otherwise name `$1` itself and pass the redirect (measured; the shape
|
|
584
|
-
# no-undo-audit.sh closed the same way
|
|
583
|
+
# no-undo-audit.sh closed the same way). The sentinel leaves `$(...)`
|
|
585
584
|
# only git's own terminating newline to strip.
|
|
586
585
|
#
|
|
587
586
|
# What this does NOT cover, the boundary release-ticket.sh's copy of this
|
|
588
|
-
# compare also states
|
|
589
|
-
# working tree stays `$1` — a `.git` naming a sibling worktree's admin dir
|
|
590
|
-
#
|
|
587
|
+
# compare also states: shapes that swap which git DIR answers while the
|
|
588
|
+
# working tree stays `$1` — a `.git` naming a sibling worktree's admin dir,
|
|
589
|
+
# or a foreign git dir whose `core.worktree` points back at `$1`.
|
|
591
590
|
# `--show-toplevel` answers `$1` for both. The dirty check reads `$1`'s real
|
|
592
591
|
# files against the borrowed index, and `git worktree remove` refuses a
|
|
593
592
|
# `.git` that does not point back at its admin dir, so neither is removed.
|
|
@@ -620,10 +619,8 @@ wt_linkage_why() {
|
|
|
620
619
|
# could not look reads exactly like a measurement that looked and found
|
|
621
620
|
# nothing. At the two merged-commit checks below, the no-match arm is what
|
|
622
621
|
# authorizes the branch delete and `git worktree remove`, so this swallow spends
|
|
623
|
-
# commits rather than merely miswording a reason:
|
|
624
|
-
#
|
|
625
|
-
# tool's own failure reported as a clean verdict about the thing it was
|
|
626
|
-
# scanning.
|
|
622
|
+
# commits rather than merely miswording a reason: a tool's own failure
|
|
623
|
+
# reported as a clean verdict about the thing it was scanning.
|
|
627
624
|
#
|
|
628
625
|
# The shape, so no call site reaches the third outcome by accident: this
|
|
629
626
|
# returns 0 whenever grep delivered a verdict at all — `$gq_rc` then holds 0
|
|
@@ -652,15 +649,15 @@ wt_linkage_why() {
|
|
|
652
649
|
# needs `$gp_o` out as text too, and a command substitution's exit status and
|
|
653
650
|
# its captured text both come from the SAME last command, so the moment
|
|
654
651
|
# something runs after grep to print a value, that later command's own exit
|
|
655
|
-
# status overwrites grep's. Grep's stderr is kept for
|
|
656
|
-
#
|
|
652
|
+
# status overwrites grep's. Grep's stderr is kept for the reason `git_probe`
|
|
653
|
+
# above keeps git's — a probe that dies naming no cause reaches an operator as
|
|
657
654
|
# a bare refusal — but keeping it costs nothing here: it IS the command
|
|
658
655
|
# substitution's text, not a second thing smuggled alongside the rc.
|
|
659
656
|
#
|
|
660
657
|
# `if gq_err=$(...); then gq_rc=0; else gq_rc=$?; fi`, never a bare
|
|
661
658
|
# `gq_err=$(...); gq_rc=$?`: under `set -e` a bare failing assignment would
|
|
662
659
|
# abort the function before `gq_rc=$?` ever ran, the same measured reason
|
|
663
|
-
# `git_probe` above takes the same shape
|
|
660
|
+
# `git_probe` above takes the same shape. A command
|
|
664
661
|
# substitution used as an `if`'s condition is exempt from `set -e` by POSIX
|
|
665
662
|
# definition, so `gq_rc=$?` always runs whether grep matched, didn't match, or
|
|
666
663
|
# broke.
|
|
@@ -678,9 +675,8 @@ wt_linkage_why() {
|
|
|
678
675
|
# report it as a clean no-match — this function's own defect, one layer down.
|
|
679
676
|
#
|
|
680
677
|
# Extra flags come AFTER the pattern (`grep_probe "$hay" "$pat" -xF`) so the
|
|
681
|
-
# pattern keeps a fixed, non-optional slot no flag list can shift it out of
|
|
682
|
-
#
|
|
683
|
-
# of it.
|
|
678
|
+
# pattern keeps a fixed, non-optional slot no flag list can shift it out of —
|
|
679
|
+
# a flag inserted ahead of a positional argument was measured to displace it.
|
|
684
680
|
grep_probe() {
|
|
685
681
|
gq_hay=$1
|
|
686
682
|
gq_pat=$2
|
|
@@ -699,7 +695,7 @@ grep_probe() {
|
|
|
699
695
|
# four-way chain, `$wt_list`/`$gq_rc`/`$gq_err` and all, as two byte-identical
|
|
700
696
|
# copies. One copy so a fix to the chain cannot land in one sweep and miss
|
|
701
697
|
# the other, same reasoning as `gp_why` taking its guards as an argument
|
|
702
|
-
# above. The two call sites still earn their own
|
|
698
|
+
# above. The two call sites still earn their own test fixtures: both
|
|
703
699
|
# pin that both sweeps actually CALL this, which one shared body cannot do by
|
|
704
700
|
# itself.
|
|
705
701
|
wt_reg_state() {
|
|
@@ -714,19 +710,19 @@ wt_reg_state() {
|
|
|
714
710
|
fi
|
|
715
711
|
}
|
|
716
712
|
|
|
717
|
-
# The registry cross-check
|
|
713
|
+
# The registry cross-check. The branch lookup below matches a
|
|
718
714
|
# `branch refs/heads/<b>` line, and an empty match lets the branch through to
|
|
719
715
|
# the delete. Measured, git 2.50.1 (Apple Git-155): eight real admin-directory
|
|
720
|
-
# faults leave `git worktree list --porcelain -z` at rc 0 — so the
|
|
721
|
-
# below never fires — while the held entry either loses its
|
|
722
|
-
# leaves the listing entirely: `HEAD` garbage, empty, missing
|
|
723
|
-
# `gitdir` missing or chmod 000; the admin directory chmod 000;
|
|
724
|
-
# replaced by a file. `$wt` came back empty and `git branch -D`
|
|
725
|
-
# then — deleted a branch a live worktree holds in all eight, its
|
|
726
|
-
# worktree" refusal fooled by the same admin state. The delete is
|
|
727
|
-
# `git update-ref -d`, which consults no worktree at all, and the holder
|
|
728
|
-
# ahead of it (`wt_holding`) reads that same listing: measured against
|
|
729
|
-
# same eight, it answers "not held" for seven and "cannot tell" only for
|
|
716
|
+
# faults leave `git worktree list --porcelain -z` at rc 0 — so the `wt_listing`
|
|
717
|
+
# failure guard below never fires — while the held entry either loses its
|
|
718
|
+
# `branch` line or leaves the listing entirely: `HEAD` garbage, empty, missing
|
|
719
|
+
# or chmod 000; `gitdir` missing or chmod 000; the admin directory chmod 000;
|
|
720
|
+
# `.git/worktrees` replaced by a file. `$wt` came back empty and `git branch -D`
|
|
721
|
+
# — the delete then — deleted a branch a live worktree holds in all eight, its
|
|
722
|
+
# own "used by worktree" refusal fooled by the same admin state. The delete is
|
|
723
|
+
# now `git update-ref -d`, which consults no worktree at all, and the holder
|
|
724
|
+
# check ahead of it (`wt_holding`) reads that same listing: measured against
|
|
725
|
+
# the same eight, it answers "not held" for seven and "cannot tell" only for
|
|
730
726
|
# `HEAD` missing, the one fault that leaves a `detached` line behind. No
|
|
731
727
|
# backstop exists past this point, so the listing has to be checked against
|
|
732
728
|
# the registry before its silence is read as "no worktree".
|
|
@@ -740,9 +736,9 @@ wt_reg_state() {
|
|
|
740
736
|
# inflight.sh's pair of the same names (inflight.sh `count_registry`,
|
|
741
737
|
# `count_linked`, the recount at `[ "$linked" -eq "$registered" ] || {
|
|
742
738
|
# count_registry && count_linked; }` and the two direction-named refusals
|
|
743
|
-
# after it) — the stray-`mkdir` skip, the count-what-`ls`-cannot-read rule
|
|
744
|
-
#
|
|
745
|
-
#
|
|
739
|
+
# after it) — the stray-`mkdir` skip, the count-what-`ls`-cannot-read rule,
|
|
740
|
+
# the `[ -r ] && [ -x ]` unreadable-registry arm and the `-ge 1` floor all
|
|
741
|
+
# carry that copy's measurements. One tightening: `-d` joins
|
|
746
742
|
# the unreadable arm, because a registry replaced by a mode-755 FILE passes
|
|
747
743
|
# `-r` and `-x`, globs to nothing, counts 0 against git's 0, and agrees.
|
|
748
744
|
#
|
|
@@ -754,7 +750,7 @@ wt_reg_state() {
|
|
|
754
750
|
# the only one that can be `bare`) is excluded, and a missing `HEAD` line
|
|
755
751
|
# reads as null, the same rule the branchless sweep's null-object-id arm
|
|
756
752
|
# applies. That arm stays as it is: it reports the worktree, while this one
|
|
757
|
-
# protects the branches. No `/^bare$/` rule here, deliberately:
|
|
753
|
+
# protects the branches. No `/^bare$/` rule here, deliberately: a test
|
|
758
754
|
# fixture selects that sweep's awk by it, and a second carrier would shim
|
|
759
755
|
# this one too.
|
|
760
756
|
#
|
|
@@ -762,25 +758,27 @@ wt_reg_state() {
|
|
|
762
758
|
# nameless entry says nothing about WHICH branch it held, so a healthy branch
|
|
763
759
|
# with no worktree is exactly as unclearable as the tampered one. The check
|
|
764
760
|
# runs on the listing each branch's own lookup reads — re-read per branch, as
|
|
765
|
-
# the
|
|
766
|
-
# branch in the pass, and a transient one keeps only
|
|
767
|
-
# listing it touched (
|
|
768
|
-
# the listing failure; this guard follows it rather than
|
|
761
|
+
# the comment at the `wt_listing` failure guard below records — so a standing
|
|
762
|
+
# fault keeps every [gone] branch in the pass, and a transient one keeps only
|
|
763
|
+
# the branches whose listing it touched (a transient-fault fixture pins that
|
|
764
|
+
# granularity for the listing failure; this guard follows it rather than
|
|
765
|
+
# latching).
|
|
769
766
|
#
|
|
770
|
-
# Recount before refusing, exactly as inflight.sh does it
|
|
767
|
+
# Recount before refusing, exactly as inflight.sh does it: the
|
|
771
768
|
# registry scan and git's listing are two reads at two instants, and a
|
|
772
769
|
# sibling's `worktree add`/`remove` landing between them makes the counts
|
|
773
770
|
# disagree with nothing wrong. Same order as that copy, first pair and recount
|
|
774
771
|
# alike: `count_registry` FIRST, git's listing SECOND — the loop takes the
|
|
775
|
-
# first registry count just ahead of the
|
|
776
|
-
# the first listing, so no extra listing is read per branch. A mutation
|
|
777
|
-
# between the first count and the listing is already reflected in the
|
|
778
|
-
# so the recount's registry scan agrees with it; the recount re-takes
|
|
779
|
-
# the same order, and re-reads the listing through `wt_listing`, so
|
|
780
|
-
# — which the lookup then scans — is the very listing the recount
|
|
772
|
+
# first registry count just ahead of the `wt_listing` failure guard, whose read
|
|
773
|
+
# is the first listing, so no extra listing is read per branch. A mutation
|
|
774
|
+
# landing between the first count and the listing is already reflected in the
|
|
775
|
+
# listing, so the recount's registry scan agrees with it; the recount re-takes
|
|
776
|
+
# BOTH, in the same order, and re-reads the listing through `wt_listing`, so
|
|
777
|
+
# `$wt_list` — which the lookup then scans — is the very listing the recount
|
|
778
|
+
# validated.
|
|
781
779
|
# inflight.sh's copy recounts once (its `[ "$linked" -eq "$registered" ] ||
|
|
782
780
|
# { count_registry && count_linked; }`); release-ticket.sh's bounds the same
|
|
783
|
-
# loop at two passes
|
|
781
|
+
# loop at two passes for a third-mutation window. This copy takes
|
|
784
782
|
# inflight.sh's single recount: a false refusal here costs one pass's wait,
|
|
785
783
|
# never a deletion, and a genuinely dropped entry is a standing state that
|
|
786
784
|
# survives every recount.
|
|
@@ -865,7 +863,7 @@ wt_registry_why() {
|
|
|
865
863
|
# refuses `has space` as invalid), so the name is always the whole of $1, and a
|
|
866
864
|
# branch with no upstream leaves $2 empty rather than matching. The tracking
|
|
867
865
|
# forms that DO carry a space, `[ahead 1]` and its siblings, split so that $2
|
|
868
|
-
# holds `[ahead` — not `[gone]` either way.
|
|
866
|
+
# holds `[ahead` — not `[gone]` either way.
|
|
869
867
|
# A command substitution inside a `for ... in` word list discards its own
|
|
870
868
|
# exit status entirely, in every shell measured here (bash, dash, macOS
|
|
871
869
|
# /bin/sh): `for x in $(false); do …; done` completes at the loop's own end,
|
|
@@ -875,8 +873,8 @@ wt_registry_why() {
|
|
|
875
873
|
# `git for-each-ref` that dies still leaves awk scanning empty input, and
|
|
876
874
|
# awk finishes that scan at rc 0 — the identical exit this loop sees on a
|
|
877
875
|
# genuinely branchless repo. awk is not immune either, and this file's
|
|
878
|
-
# header already documents an awk that cannot finish a scan (the
|
|
879
|
-
#
|
|
876
|
+
# header already documents an awk that cannot finish a scan (the multibyte
|
|
877
|
+
# trigger). Either failure, unguarded, reads as a clean sweep
|
|
880
878
|
# that never looked: no branches matched because none was ever seen,
|
|
881
879
|
# indistinguishable from none being reapable.
|
|
882
880
|
#
|
|
@@ -889,17 +887,17 @@ wt_registry_why() {
|
|
|
889
887
|
# branchless sweep's own enumeration guard below (`if ! wt_listing`), for
|
|
890
888
|
# the same reason — dying here would also abort the second sweep and the
|
|
891
889
|
# final `worktree prune`, neither of which this enumeration failing has
|
|
892
|
-
# anything to do with, over a failure
|
|
890
|
+
# anything to do with, over a failure that only defers reaping to a later pass.
|
|
893
891
|
if ! git_probe for-each-ref --format='%(refname) %(upstream:track)' refs/heads; then
|
|
894
892
|
keep "" "could not enumerate [gone] branches — none reaped, and none reported reapable either$(gp_why)"
|
|
895
893
|
gone_branches=""
|
|
896
894
|
else
|
|
897
895
|
# git_probe captures git's stderr into $gp_err instead of leaving it on the
|
|
898
|
-
# real fd — the whole reason it exists
|
|
899
|
-
#
|
|
896
|
+
# real fd — the whole reason it exists — and every OTHER call site in this
|
|
897
|
+
# file reads $gp_err back out through a targeted check (gp_cut_short,
|
|
900
898
|
# gp_why) before falling through. This call site's success path does
|
|
901
|
-
# neither: an rc-0 `for-each-ref` that still WARNS
|
|
902
|
-
#
|
|
899
|
+
# neither: an rc-0 `for-each-ref` that still WARNS used to reach the
|
|
900
|
+
# operator's stderr directly, back when this was a plain
|
|
903
901
|
# `git … | awk …` pipeline with git's stderr inherited, and now reaches no
|
|
904
902
|
# one unless forwarded here explicitly.
|
|
905
903
|
[ -z "$gp_err" ] || printf '%s' "$gp_err" >&2
|
|
@@ -914,14 +912,14 @@ for b in $gone_branches; do
|
|
|
914
912
|
# SHA rather than the live ref: the cherry below runs against `$tip`, and
|
|
915
913
|
# the delete at the foot of this loop is `git update-ref -d refs/heads/$b
|
|
916
914
|
# $tip`, which refuses unless the ref STILL equals `$tip` at that instant.
|
|
917
|
-
#
|
|
915
|
+
# The cherry once read `refs/heads/$b` and the delete was
|
|
918
916
|
# `git branch -D "$b"`, a separate call that deletes whatever the ref holds
|
|
919
917
|
# when it runs — so a commit landing between the two was force-deleted at
|
|
920
|
-
# rc 0: the check-then-delete gap release-ticket.sh
|
|
921
|
-
#
|
|
918
|
+
# rc 0: the check-then-delete gap release-ticket.sh's own delete closes the
|
|
919
|
+
# same way. A tip that cannot be read is a keep, never a delete.
|
|
922
920
|
#
|
|
923
921
|
# `git_probe`, never `2>&1` into the capture: `$tip` is used as a SHA, and a
|
|
924
|
-
# stray `~/.gitconfig` warning git prints at rc 0
|
|
922
|
+
# stray `~/.gitconfig` warning git prints at rc 0 would arrive glued
|
|
925
923
|
# onto it. git's own words still reach the reason, through `gp_why`.
|
|
926
924
|
if ! git_probe rev-parse --verify "refs/heads/$b"; then
|
|
927
925
|
keep "$b" "cannot read the branch tip — not deleted$(gp_why)"
|
|
@@ -959,8 +957,8 @@ for b in $gone_branches; do
|
|
|
959
957
|
# name the same commit — and it is the same key the worktree lookup below
|
|
960
958
|
# already builds.
|
|
961
959
|
#
|
|
962
|
-
# `$base_rev` is the other side of the same rule, and it was missing
|
|
963
|
-
#
|
|
960
|
+
# `$base_rev` is the other side of the same rule, and it was once missing:
|
|
961
|
+
# `$base` reached this `git cherry` exactly as BASE_REF spelled it, so a
|
|
964
962
|
# local tag named `origin/main` outranked refs/remotes/origin/main and the
|
|
965
963
|
# probe answered about the TAG while `git branch -D`, the delete then,
|
|
966
964
|
# deleted the BRANCH — measured, an unmerged [gone] branch whose commit
|
|
@@ -969,7 +967,7 @@ for b in $gone_branches; do
|
|
|
969
967
|
# records why the accept-list beside it is what makes prefixing sound. Being
|
|
970
968
|
# the only merge check bounds what ELSE could catch an unmerged branch, not
|
|
971
969
|
# whether this check itself can be wrong — which is why BOTH revs it
|
|
972
|
-
# consumes are qualified.
|
|
970
|
+
# consumes are qualified.
|
|
973
971
|
if ! cherry=$(git cherry "$base_rev" "$tip" 2>&1); then
|
|
974
972
|
keep "$b" "cherry probe failed — cannot tell if merged: $(printf '%s' "$cherry" | tr '\n' ' ')"
|
|
975
973
|
continue
|
|
@@ -983,7 +981,7 @@ for b in $gone_branches; do
|
|
|
983
981
|
#
|
|
984
982
|
# What "grep's is the only status left to take" missed, and what this shape
|
|
985
983
|
# exists for: taking it is not the same as READING it. grep answers three
|
|
986
|
-
# ways, and
|
|
984
|
+
# ways, and the `if` once had two arms — an rc 2 scan that never
|
|
987
985
|
# examined `$cherry` fell into the merged arm, and no check between here and
|
|
988
986
|
# the delete below asks whether the branch is merged. So the deletion went
|
|
989
987
|
# ahead on a merge status no tool had established. `grep_probe` splits the two
|
|
@@ -1000,8 +998,8 @@ for b in $gone_branches; do
|
|
|
1000
998
|
|
|
1001
999
|
# The registry is counted BEFORE the listing below is read — inflight.sh's
|
|
1002
1000
|
# order, which `wt_registry_why`'s recount comment explains. A registry that
|
|
1003
|
-
# cannot be read sets `reg_why` here and is refused after the
|
|
1004
|
-
# a listing failure still reports as one.
|
|
1001
|
+
# cannot be read sets `reg_why` here and is refused after the `wt_listing`
|
|
1002
|
+
# failure guard, so a listing failure still reports as one.
|
|
1005
1003
|
reg_why=
|
|
1006
1004
|
count_registry || :
|
|
1007
1005
|
|
|
@@ -1021,26 +1019,27 @@ for b in $gone_branches; do
|
|
|
1021
1019
|
# own. Keeping it strands every [gone] branch in this pass on one repo-level
|
|
1022
1020
|
# failure, since the listing is re-read per branch (header: every
|
|
1023
1021
|
# precondition is recomputed); reap runs after every merge pass, so each waits
|
|
1024
|
-
# one pass with the cause named.
|
|
1022
|
+
# one pass with the cause named.
|
|
1025
1023
|
#
|
|
1026
1024
|
# A genuine awk failure is a DIFFERENT fault from the listing failing, and is
|
|
1027
1025
|
# guarded separately: it fires only when `wt_listing` itself succeeded — a
|
|
1028
1026
|
# real, non-empty `$wt_list` — and awk could not finish scanning it (the
|
|
1029
|
-
#
|
|
1030
|
-
#
|
|
1031
|
-
#
|
|
1032
|
-
#
|
|
1027
|
+
# multibyte trigger this file's header documents). Left bare, that failure
|
|
1028
|
+
# aborted the whole script on awk's own diagnostic, with no `reap:`-prefixed
|
|
1029
|
+
# line for a caller to grep stderr for — the same shape release-ticket.sh's
|
|
1030
|
+
# own copy of this lookup was fixed for. `keep`, not `die`:
|
|
1033
1031
|
# nothing has mutated $b yet, and dying here would also discard whatever
|
|
1034
1032
|
# earlier iterations of this loop already reaped — the same reason the
|
|
1035
1033
|
# branchless sweep below keeps rather than dies on its own copy of this pipe,
|
|
1036
|
-
# and the same reason the listing failure above keeps.
|
|
1034
|
+
# and the same reason the listing failure above keeps.
|
|
1037
1035
|
if ! wt_listing; then
|
|
1038
1036
|
keep "$b" "worktree lookup failed — cannot tell whether $b has a worktree; kept until a pass that can read the registry: $(printf '%s' "$wt_err" | tr '\n' ' ')"
|
|
1039
1037
|
continue
|
|
1040
1038
|
fi
|
|
1041
1039
|
# A listing that READ is not yet a listing that can be trusted: see
|
|
1042
|
-
# `wt_registry_why` above. After the
|
|
1043
|
-
# lookup scans the listing this check validated (a recount
|
|
1040
|
+
# `wt_registry_why` above. After the `wt_listing` failure guard, before the
|
|
1041
|
+
# lookup, so the lookup scans the listing this check validated (a recount
|
|
1042
|
+
# re-reads it).
|
|
1044
1043
|
if ! wt_registry_why; then
|
|
1045
1044
|
keep "$b" "worktree registry inconsistent — $reg_why; every [gone] branch is kept until a pass that reads a consistent registry"
|
|
1046
1045
|
continue
|
|
@@ -1058,7 +1057,7 @@ for b in $gone_branches; do
|
|
|
1058
1057
|
# made on the `branch` line, so only the path this sweep REPORTS and acts on
|
|
1059
1058
|
# was wrong. `wt_listing` now delivers the whole path with the newline
|
|
1060
1059
|
# substituted, and a substituted path is one no `git -C` or `worktree remove`
|
|
1061
|
-
# here can name — so it is refused rather than acted on.
|
|
1060
|
+
# here can name — so it is refused rather than acted on.
|
|
1062
1061
|
#
|
|
1063
1062
|
# `nl_path ""` is false, so a branch with no worktree falls through to the
|
|
1064
1063
|
# `[ -n "$wt" ]` below exactly as before.
|
|
@@ -1078,8 +1077,7 @@ for b in $gone_branches; do
|
|
|
1078
1077
|
#
|
|
1079
1078
|
# `-e` is this `if`'s own condition, so existence is settled before any
|
|
1080
1079
|
# git command runs through $wt: a genuinely deleted directory never
|
|
1081
|
-
# reaches a status call that would fail on it and read as dirty forever
|
|
1082
|
-
# (#83).
|
|
1080
|
+
# reaches a status call that would fail on it and read as dirty forever.
|
|
1083
1081
|
if [ -e "$wt" ]; then
|
|
1084
1082
|
# Establish the .git linkage exists before trusting anything git says
|
|
1085
1083
|
# through it. Delete a worktree's .git file outright and `git -C` does
|
|
@@ -1094,9 +1092,9 @@ for b in $gone_branches; do
|
|
|
1094
1092
|
# `git worktree add` always writes `.git` as a regular file — so unlike
|
|
1095
1093
|
# worktree-audit.sh this does not also need to accept a `.git`
|
|
1096
1094
|
# directory. This `-f` test establishes only that the linkage EXISTS,
|
|
1097
|
-
# the same gate release-ticket.sh
|
|
1095
|
+
# the same gate release-ticket.sh and worktree-audit.sh carry;
|
|
1098
1096
|
# that it answers for `$wt` is established by the same-directory
|
|
1099
|
-
# `--show-toplevel` compare right after it (`wt_linkage_why
|
|
1097
|
+
# `--show-toplevel` compare right after it (`wt_linkage_why`).
|
|
1100
1098
|
# The main checkout reaches here, and must be answered before the
|
|
1101
1099
|
# linkage guard below sees it. `git worktree list --porcelain` emits a
|
|
1102
1100
|
# `branch refs/heads/...` line for the main worktree too, so a `[gone]`
|
|
@@ -1113,7 +1111,7 @@ for b in $gone_branches; do
|
|
|
1113
1111
|
# and say which, in the dry run and under --apply alike — the plain `-f`
|
|
1114
1112
|
# guard printed a false cause,
|
|
1115
1113
|
# and dropping it entirely leaves the dry run promising a reap that can
|
|
1116
|
-
# never happen
|
|
1114
|
+
# never happen.
|
|
1117
1115
|
if [ -d "$wt/.git" ] && [ -f "$wt/.git/HEAD" ]; then
|
|
1118
1116
|
keep "$b" "worktree $wt is the main checkout — cannot remove it or delete the branch checked out in it"
|
|
1119
1117
|
continue
|
|
@@ -1144,30 +1142,30 @@ for b in $gone_branches; do
|
|
|
1144
1142
|
# `--porcelain -uall` -> rc 0, `?? sub/deep.txt` …
|
|
1145
1143
|
#
|
|
1146
1144
|
# This is the one shape the fail-closed `if ! …` idiom structurally
|
|
1147
|
-
# cannot see, because the status IS 0 —
|
|
1148
|
-
# `git cherry` swallow
|
|
1149
|
-
# rc was non-zero and taking the status was the whole fix. Nor can
|
|
1150
|
-
# stderr
|
|
1151
|
-
# stderr, so there is nothing for `gp_cut_short` to
|
|
1152
|
-
# mode on the command line is the only fix: a probe
|
|
1153
|
-
# licenses an action pins an explicit mode; a probe
|
|
1154
|
-
# after a gate has already refused need not (see
|
|
1155
|
-
# remove`'s own refusal is no backstop, being the
|
|
1156
|
-
# same config silences (measured at the --apply call
|
|
1145
|
+
# cannot see, because the status IS 0 — the rc-0 sibling of the
|
|
1146
|
+
# `git cherry` swallow this file's branch sweep already documents, where
|
|
1147
|
+
# rc was non-zero and taking the status was the whole fix. Nor can
|
|
1148
|
+
# `git_probe`'s stderr capture reach it: the config yields rc 0, empty
|
|
1149
|
+
# stdout AND empty stderr, so there is nothing for `gp_cut_short` to
|
|
1150
|
+
# match. Pinning the mode on the command line is the only fix: a probe
|
|
1151
|
+
# whose EMPTY answer licenses an action pins an explicit mode; a probe
|
|
1152
|
+
# that only reports after a gate has already refused need not (see
|
|
1153
|
+
# below). `git worktree remove`'s own refusal is no backstop, being the
|
|
1154
|
+
# same machinery the same config silences (measured at the --apply call
|
|
1155
|
+
# below).
|
|
1157
1156
|
#
|
|
1158
1157
|
# The one bare `--porcelain` left in a SCRIPT is deliberate:
|
|
1159
1158
|
# instruments.sh prints one to stderr to say WHAT changed, after a digest
|
|
1160
1159
|
# over `git ls-files` has already refused. That digest covers TRACKED
|
|
1161
1160
|
# files only, so no untracked file can trigger it and the silenced mode
|
|
1162
1161
|
# cannot hide the thing being reported. A report, not a gate. (Prose
|
|
1163
|
-
# instructions to an agent are a separate inventory — see SKILL.md
|
|
1164
|
-
#
|
|
1165
|
-
# alongside the scripts.)
|
|
1162
|
+
# instructions to an agent are a separate inventory — see SKILL.md,
|
|
1163
|
+
# pinned alongside the scripts.)
|
|
1166
1164
|
#
|
|
1167
1165
|
# `-uall` here, not `-unormal`: both override the config, but this probe
|
|
1168
1166
|
# IS the dirty gate itself (unlike the `--ignored` reason-string probe
|
|
1169
1167
|
# below, whose keep/reap verdict does not depend on per-file detail),
|
|
1170
|
-
# and `-uall` is the form
|
|
1168
|
+
# and `-uall` is the form measured against this site.
|
|
1171
1169
|
if ! git_probe -C "$wt" status --porcelain -uall; then
|
|
1172
1170
|
keep "$b" "worktree $wt could not be read$(gp_why)"
|
|
1173
1171
|
continue
|
|
@@ -1212,7 +1210,7 @@ for b in $gone_branches; do
|
|
|
1212
1210
|
# fixture: under that config `--porcelain --ignored` answers 0
|
|
1213
1211
|
# bytes at rc 0 — the `!!` lines are suppressed too, so a precious
|
|
1214
1212
|
# ignored file reads as absent — while `--porcelain -unormal
|
|
1215
|
-
# --ignored` lists both `??` and `!!` entries.
|
|
1213
|
+
# --ignored` lists both `??` and `!!` entries.
|
|
1216
1214
|
#
|
|
1217
1215
|
# `-unormal`, not `-uall`, here: this probe only builds the
|
|
1218
1216
|
# human-readable "keep" reason string below, and the keep/reap
|
|
@@ -1229,8 +1227,8 @@ for b in $gone_branches; do
|
|
|
1229
1227
|
continue
|
|
1230
1228
|
fi
|
|
1231
1229
|
# `--ignored` asks git to OPEN every ignored path to list what is
|
|
1232
|
-
# inside it (measured
|
|
1233
|
-
#
|
|
1230
|
+
# inside it (measured: a `chmod 000` ignored directory made this
|
|
1231
|
+
# exact probe warn and exit 0). A precious
|
|
1234
1232
|
# ignored file under a path git could not open would never reach
|
|
1235
1233
|
# $ignored, and `git worktree remove` deletes ignored files
|
|
1236
1234
|
# silently — so a cut-short walk fails closed rather than report what
|
|
@@ -1241,7 +1239,7 @@ for b in $gone_branches; do
|
|
|
1241
1239
|
fi
|
|
1242
1240
|
# `paste`, not `awk`, used to be this substitution's last stage, so
|
|
1243
1241
|
# the substitution reported PASTE's status only — an awk that could
|
|
1244
|
-
# not finish scanning `$gp_out` (the
|
|
1242
|
+
# not finish scanning `$gp_out` (the multibyte trigger) failed
|
|
1245
1243
|
# silently AND invisibly: unlike the bare assignments above, nothing
|
|
1246
1244
|
# here even reads as "empty means none", because the captured
|
|
1247
1245
|
# pipeline still succeeds — paste has nothing of its own to fail on
|
|
@@ -1250,7 +1248,7 @@ for b in $gone_branches; do
|
|
|
1250
1248
|
# `jstr`'s `sed | tr` ("EVERY FALLIBLE STAGE'S STATUS IS READ") and
|
|
1251
1249
|
# the shape release-ticket.sh's own worktree lookups already take.
|
|
1252
1250
|
# `keep`, not `die`, for the reason the worktree lookup above gives:
|
|
1253
|
-
# this is per-branch and nothing has mutated $b yet.
|
|
1251
|
+
# this is per-branch and nothing has mutated $b yet.
|
|
1254
1252
|
if ! ignored_lines=$(printf '%s\n' "$gp_out" | awk '/^!! /{sub(/^!! /,""); print}'); then
|
|
1255
1253
|
keep "$b" "worktree $wt ignored-files scan failed — treating it as unresolved rather than guessing it has none"
|
|
1256
1254
|
continue
|
|
@@ -1271,9 +1269,9 @@ for b in $gone_branches; do
|
|
|
1271
1269
|
fi
|
|
1272
1270
|
|
|
1273
1271
|
# Refused before the removal below, and in the dry run as well as under
|
|
1274
|
-
# `--apply`, for the reason the main-checkout guard above records
|
|
1272
|
+
# `--apply`, for the reason the main-checkout guard above records: a
|
|
1275
1273
|
# `would remove worktree` line the next `--apply` refuses is a promise this
|
|
1276
|
-
# script cannot keep. Unlike git's own refusals
|
|
1274
|
+
# script cannot keep. Unlike git's own refusals this one IS
|
|
1277
1275
|
# predictable — the cwd is known before anything is deleted.
|
|
1278
1276
|
#
|
|
1279
1277
|
# Below the probes rather than above them, so every reason already true of
|
|
@@ -1285,15 +1283,15 @@ for b in $gone_branches; do
|
|
|
1285
1283
|
# `continue`, so the branch is kept with its worktree — the pairing the
|
|
1286
1284
|
# main-checkout reason already states, and the holder check before the
|
|
1287
1285
|
# delete would refuse a branch checked out in a surviving worktree anyway.
|
|
1288
|
-
# #992
|
|
1289
1286
|
#
|
|
1290
1287
|
# Ancestor match, not exact equality: a worktree nested inside `$wt`
|
|
1291
1288
|
# (a real, documented shape — SKILL.md names a member committing from a
|
|
1292
1289
|
# nested worktree) has `$wt` as an ancestor on disk, so removing `$wt`
|
|
1293
1290
|
# removes the nested one's files too — taking any uncommitted work in it
|
|
1294
|
-
# along, the
|
|
1295
|
-
# `$wt` itself never equals `$self_wt` in that shape
|
|
1296
|
-
# carries the match and why it is on the directory, not only
|
|
1291
|
+
# along, the same cwd deletion this guard exists for, one path further
|
|
1292
|
+
# out — even though `$wt` itself never equals `$self_wt` in that shape.
|
|
1293
|
+
# `holds_cwd` carries the match and why it is on the directory, not only
|
|
1294
|
+
# the string.
|
|
1297
1295
|
if holds_cwd "$wt"; then
|
|
1298
1296
|
keep "$b" "worktree $wt holds the working directory this run was started in — removing it would delete the cwd every git call after it needs; rerun from outside it"
|
|
1299
1297
|
continue
|
|
@@ -1311,7 +1309,7 @@ for b in $gone_branches; do
|
|
|
1311
1309
|
# 2.50.1 (Apple Git-155), with a control: with `status.showUntrackedFiles
|
|
1312
1310
|
# = no` set, removing a worktree holding an untracked file exits 0 and
|
|
1313
1311
|
# takes the file with it; the identical fixture without that config exits
|
|
1314
|
-
# 128 refusing. That is why the probes above pin `-uall`
|
|
1312
|
+
# 128 refusing. That is why the probes above pin `-uall` and why
|
|
1315
1313
|
# this line may not be read as a second opinion: the config that silences
|
|
1316
1314
|
# them silences this too, so the gate above is the ONLY thing standing
|
|
1317
1315
|
# here. The ignored-file gap it never covers under any config is handled
|
|
@@ -1331,15 +1329,14 @@ for b in $gone_branches; do
|
|
|
1331
1329
|
# documents), and `chmod 555 .git/worktrees/<id>` deletes the whole
|
|
1332
1330
|
# directory while the entry stays listed. So a cleared registration is no
|
|
1333
1331
|
# evidence of an orphan, an intact one is no evidence that nothing was
|
|
1334
|
-
# removed, and naming a filesystem state nobody probed would be
|
|
1335
|
-
#
|
|
1336
|
-
#
|
|
1337
|
-
#
|
|
1338
|
-
#
|
|
1339
|
-
#
|
|
1340
|
-
#
|
|
1341
|
-
#
|
|
1342
|
-
# stat can.
|
|
1332
|
+
# removed, and naming a filesystem state nobody probed would be the very
|
|
1333
|
+
# defect this re-read exists to fix — a reason naming something other
|
|
1334
|
+
# than what was measured. reap.sh and release-ticket.sh once answered an
|
|
1335
|
+
# unreadable worktree in opposite directions; that is closed, and a third
|
|
1336
|
+
# filesystem probe here would reopen exactly that ground. `gone()` above
|
|
1337
|
+
# is deliberately not reused: it answers a harder question (established
|
|
1338
|
+
# absence vs an unsearchable prefix) that a registry read does not have,
|
|
1339
|
+
# and cannot fail the way a stat can.
|
|
1343
1340
|
#
|
|
1344
1341
|
# Captured, not piped: `git … | grep -q` takes grep's status, never
|
|
1345
1342
|
# git's — the same swallow fixed for `git cherry` above, which the probe
|
|
@@ -1352,7 +1349,7 @@ for b in $gone_branches; do
|
|
|
1352
1349
|
# as a measurement. Nothing on disk turns on it — both arms keep and
|
|
1353
1350
|
# continue — which is exactly why it is a REASON bug and not a deletion
|
|
1354
1351
|
# bug, and why the unanswerable arm here joins the existing
|
|
1355
|
-
# unread-listing arm rather than inventing a third verdict.
|
|
1352
|
+
# unread-listing arm rather than inventing a third verdict.
|
|
1356
1353
|
#
|
|
1357
1354
|
# Still keep, still continue, and nothing on disk is touched either way:
|
|
1358
1355
|
# one refusal must not strand the remaining branches of an unattended
|
|
@@ -1371,8 +1368,8 @@ for b in $gone_branches; do
|
|
|
1371
1368
|
|
|
1372
1369
|
if [ "$apply" = true ]; then
|
|
1373
1370
|
# What the compare-and-swap below does not give back: `git update-ref` is
|
|
1374
|
-
# ref-only plumbing and, unlike `git branch -D` (
|
|
1375
|
-
#
|
|
1371
|
+
# ref-only plumbing and, unlike `git branch -D` (this sweep's former
|
|
1372
|
+
# delete), consults no worktree at all. `-D`'s own delete-time refusal on a
|
|
1376
1373
|
# branch a worktree holds is replaced by worktree.sh's `wt_holding`, over
|
|
1377
1374
|
# the listing re-read here rather than the one the `$wt` lookup above
|
|
1378
1375
|
# read: the `worktree remove` above has changed it since, and a
|
|
@@ -1382,19 +1379,19 @@ for b in $gone_branches; do
|
|
|
1382
1379
|
# `$wt` lookup never binds because the listing prints no `branch` line for
|
|
1383
1380
|
# it. Measured, git 2.50.1: `-D` refuses both, `update-ref -d` deletes
|
|
1384
1381
|
# both, and the sibling's `rebase --continue` then fails on `cannot lock
|
|
1385
|
-
# ref
|
|
1382
|
+
# ref`. A worktree the reader cannot resolve is a keep,
|
|
1386
1383
|
# never "not held".
|
|
1387
1384
|
#
|
|
1388
1385
|
# Under --apply only, like the delete it guards: in the dry run the
|
|
1389
1386
|
# worktree the `$wt` lookup found is still registered, and would read as a
|
|
1390
1387
|
# holder of the very branch it pairs with. The dry run therefore cannot
|
|
1391
1388
|
# predict THIS branch's own refusal — but not "exactly as it could not
|
|
1392
|
-
# predict `-D`'s"
|
|
1389
|
+
# predict `-D`'s": `-D`'s blind spot here was only ever this
|
|
1393
1390
|
# branch's own paired worktree. A registry read that fails closed for an
|
|
1394
1391
|
# UNRELATED worktree elsewhere in the listing (reaping.md) keeps every
|
|
1395
1392
|
# `[gone]` branch in the pass, a repo-wide case `-D` had no equivalent of
|
|
1396
1393
|
# — it needed no registry answer at all and failed OPEN on one it could
|
|
1397
|
-
# not read
|
|
1394
|
+
# not read. The dry run — printing `would reap` unconditionally
|
|
1398
1395
|
# here — cannot predict any of those keeps either.
|
|
1399
1396
|
#
|
|
1400
1397
|
# A window remains between this re-read and the delete. A commit landing
|
|
@@ -1425,7 +1422,7 @@ for b in $gone_branches; do
|
|
|
1425
1422
|
# landing since is refused with git's `cannot lock ref … is at <new> but
|
|
1426
1423
|
# expected <tip>`, branch and commit intact. Never plain `git branch -d`:
|
|
1427
1424
|
# upstream is gone, so it compares against a possibly-behind local HEAD
|
|
1428
|
-
# and refuses everything here
|
|
1425
|
+
# and refuses everything here.
|
|
1429
1426
|
#
|
|
1430
1427
|
# `--no-deref`: measured, git 2.50.1, `update-ref -d` on a branch that is
|
|
1431
1428
|
# a symbolic ref deletes the branch it POINTS AT and leaves the symref
|
|
@@ -1433,8 +1430,7 @@ for b in $gone_branches; do
|
|
|
1433
1430
|
#
|
|
1434
1431
|
# `2>&1` into the capture, and update-ref prints nothing on stdout: a bare
|
|
1435
1432
|
# "branch delete failed" names the step, never the fault, and git's own
|
|
1436
|
-
# diagnosis is the only thing that tells an operator which remedy applies
|
|
1437
|
-
# (#391).
|
|
1433
|
+
# diagnosis is the only thing that tells an operator which remedy applies.
|
|
1438
1434
|
if ! err=$(git update-ref --no-deref -d "refs/heads/$b" "$tip" 2>&1); then
|
|
1439
1435
|
keep "$b" "branch delete failed: $(printf '%s' "$err" | tr '\n' ' ')"
|
|
1440
1436
|
continue
|
|
@@ -1480,16 +1476,16 @@ done
|
|
|
1480
1476
|
# line was never refused — it was never considered, which is why the
|
|
1481
1477
|
# no-silent-caps rule did not fire either: no `would remove worktree` line, no
|
|
1482
1478
|
# `kept` entry, and the directory left on disk while its branch was reaped
|
|
1483
|
-
# (
|
|
1479
|
+
# (measured live during a merge pass). A stale worktree still answers
|
|
1484
1480
|
# `git worktree list` and inflight.sh reads one as a live claim, so an
|
|
1485
1481
|
# already-merged ticket then reads as taken and the candidate queue shrinks
|
|
1486
1482
|
# with nothing reporting it.
|
|
1487
1483
|
#
|
|
1488
1484
|
# What leaves a fleet worktree detached is NOT recorded here, deliberately. An
|
|
1489
|
-
# earlier draft of this comment blamed the merge bot's server-side rebase
|
|
1490
|
-
#
|
|
1491
|
-
# `path=rebase` for
|
|
1492
|
-
#
|
|
1485
|
+
# earlier draft of this comment blamed the merge bot's server-side rebase and
|
|
1486
|
+
# that mechanism is measured false: in a later pass the bot reported
|
|
1487
|
+
# `path=rebase` for three PRs, and a `reap.sh` dry run immediately after
|
|
1488
|
+
# printed `would remove worktree` for all three — a line only an ATTACHED
|
|
1493
1489
|
# worktree reaches. run-merge-bot.md says the same for that step: the API
|
|
1494
1490
|
# rebased the remote, not your checkout, which is left attached and merely
|
|
1495
1491
|
# stale. The shape is observed; the route to it is not established, and
|
|
@@ -1524,11 +1520,11 @@ if ! wt_listing; then
|
|
|
1524
1520
|
#
|
|
1525
1521
|
# Status taken, not swallowed: this pipeline's last command is the awk, so an
|
|
1526
1522
|
# awk that could not run leaves `$detached` empty and every branchless worktree
|
|
1527
|
-
# goes unmentioned —
|
|
1528
|
-
# branch sweep above takes both statuses too — the listing's
|
|
1529
|
-
# and keeps the branch on either
|
|
1523
|
+
# goes unmentioned — the very silence this sweep exists to end, committed
|
|
1524
|
+
# inside it. The branch sweep above takes both statuses too — the listing's
|
|
1525
|
+
# and its awk's — and keeps the branch on either.
|
|
1530
1526
|
#
|
|
1531
|
-
# Pinned
|
|
1527
|
+
# Pinned at the same arm the paragraph above admits to: a test in the suite
|
|
1532
1528
|
# shims a failing `awk` onto PATH, selected by this program's own `/^bare$/`
|
|
1533
1529
|
# rule, over a repo holding one detached worktree, and requires the decline
|
|
1534
1530
|
# below with an EMPTY removal list. Swallow this status and that fixture's
|
|
@@ -1566,7 +1562,7 @@ else
|
|
|
1566
1562
|
# `read -r` line above, so this sweep saw a prefix and, being the sweep that
|
|
1567
1563
|
# deletes branchless worktrees, could authorise a removal against it.
|
|
1568
1564
|
# `wt_listing` keeps the record and the line whole; the substituted byte is
|
|
1569
|
-
# what no command here can name, so the entry is kept and reported.
|
|
1565
|
+
# what no command here can name, so the entry is kept and reported.
|
|
1570
1566
|
if nl_path "$wt"; then
|
|
1571
1567
|
keep "" "worktree $wt holds a newline in its path — nothing here can stat it, so whether its work has landed is unknown"
|
|
1572
1568
|
continue
|
|
@@ -1577,7 +1573,7 @@ else
|
|
|
1577
1573
|
# It reaches this sweep whenever it is itself detached, it is never under
|
|
1578
1574
|
# `.worktrees/`, and this test needs nothing the probes below establish —
|
|
1579
1575
|
# both operands are false for a path that does not exist. Still ahead of the
|
|
1580
|
-
# linkage test for the reason the branch sweep records
|
|
1576
|
+
# linkage test for the reason the branch sweep records: that test would
|
|
1581
1577
|
# otherwise call the main checkout's `.git` DIRECTORY a broken linkage.
|
|
1582
1578
|
if [ -d "$wt/.git" ] && [ -f "$wt/.git/HEAD" ]; then
|
|
1583
1579
|
keep "" "worktree $wt is the main checkout — cannot remove it"
|
|
@@ -1590,14 +1586,15 @@ else
|
|
|
1590
1586
|
# evidence to read: branchless, clean and patch-equivalent to `$base` also
|
|
1591
1587
|
# describes a human's `git worktree add --detach` scratch checkout that was
|
|
1592
1588
|
# never a fleet ticket, and without this bound `--apply` deleted it
|
|
1593
|
-
# (measured
|
|
1594
|
-
#
|
|
1595
|
-
#
|
|
1589
|
+
# (measured: the same fixture survives the branch-only script and is
|
|
1590
|
+
# DELETED by the branchless one). `*/.worktrees/*` is the fleet's own
|
|
1591
|
+
# worktree home — the set this sweep exists for — and the same key
|
|
1596
1592
|
# claim-ticket.sh builds its paths under.
|
|
1597
1593
|
#
|
|
1598
|
-
# A `keep`, never a silent `continue`: a directory this script looked at
|
|
1599
|
-
# walked past with nothing said is the exact defect
|
|
1600
|
-
# the reason has to survive being read by someone who expected
|
|
1594
|
+
# A `keep`, never a silent `continue`: a directory this script looked at
|
|
1595
|
+
# and walked past with nothing said is the exact defect this sweep exists
|
|
1596
|
+
# to end, and the reason has to survive being read by someone who expected
|
|
1597
|
+
# a removal.
|
|
1601
1598
|
#
|
|
1602
1599
|
# It is also why this sweep carries no `--ignored` probe, unlike the branch
|
|
1603
1600
|
# sweep: that probe exists to protect a .env or a scratch note in a worktree
|
|
@@ -1614,7 +1611,7 @@ else
|
|
|
1614
1611
|
# emits none for a worktree whose HEAD it could not resolve, which it
|
|
1615
1612
|
# reports as the null object id — a `chmod 000` or garbage admin `HEAD`
|
|
1616
1613
|
# file, a dangling symlink or a directory standing in for one. Those are
|
|
1617
|
-
# the four routes
|
|
1614
|
+
# the four routes measured against release-ticket.sh's own lookup, and
|
|
1618
1615
|
# they empty this key exactly as a detached HEAD does. Nothing about such a
|
|
1619
1616
|
# worktree can be decided — there is no commit to probe for merged-ness —
|
|
1620
1617
|
# so it is reported and left, the same fail-closed direction the cherry
|
|
@@ -1637,12 +1634,13 @@ else
|
|
|
1637
1634
|
# upstream. Captured, never piped into `grep -q`, for the reason the branch
|
|
1638
1635
|
# sweep above records: the pipeline would take grep's status and a probe
|
|
1639
1636
|
# that died would read identically to a clean one. `$head` is a full object
|
|
1640
|
-
# id, so no refname can shadow it the way
|
|
1641
|
-
# name — but the BASE side is a shorthand until it is
|
|
1642
|
-
# sweep removes DIRECTORIES, so the
|
|
1643
|
-
#
|
|
1644
|
-
# `origin/main` at a detached
|
|
1645
|
-
#
|
|
1637
|
+
# id, so no refname can shadow it the way a tag was measured shadowing a
|
|
1638
|
+
# bare branch name — but the BASE side is a shorthand until it is
|
|
1639
|
+
# qualified, and this sweep removes DIRECTORIES, so the tag shadowing the
|
|
1640
|
+
# top of the file records costs the files themselves here and not only a
|
|
1641
|
+
# branch ref: measured, a local tag named `origin/main` at a detached
|
|
1642
|
+
# worktree's own tip made this probe read clean and `--apply` deleted the
|
|
1643
|
+
# worktree holding the only copy of that commit.
|
|
1646
1644
|
# `$base_rev` is built at the top of the file; the branch sweep's copy of
|
|
1647
1645
|
# this probe carries the same qualification for the same reason.
|
|
1648
1646
|
if ! cherry=$(git cherry "$base_rev" "$head" 2>&1); then
|
|
@@ -1652,7 +1650,7 @@ else
|
|
|
1652
1650
|
# Three-way, for the reason the branch sweep's copy of this check records
|
|
1653
1651
|
# in full: grep's rc 2 is not its rc 1, and the no-match arm here reaches
|
|
1654
1652
|
# `git worktree remove`, so the swallow cost DIRECTORIES in this sweep and
|
|
1655
|
-
# not only a branch ref.
|
|
1653
|
+
# not only a branch ref.
|
|
1656
1654
|
if ! grep_probe "$cherry" '^+'; then
|
|
1657
1655
|
keep "" "cherry scan failed — cannot tell if worktree $wt is merged$(gp_why "$gq_err")"
|
|
1658
1656
|
continue
|
|
@@ -1664,10 +1662,10 @@ else
|
|
|
1664
1662
|
if [ -e "$wt" ]; then
|
|
1665
1663
|
# The remaining guards the branch sweep above documents, in the same order
|
|
1666
1664
|
# and for the same measured reasons — the main checkout already answered
|
|
1667
|
-
# for above, the linkage established — present
|
|
1668
|
-
# for `$wt` itself
|
|
1665
|
+
# for above, the linkage established — present, then answering
|
|
1666
|
+
# for `$wt` itself — before anything git says through `$wt` is
|
|
1669
1667
|
# trusted, and existence settled by this `if` so a deleted directory
|
|
1670
|
-
# never reaches a status call that would read as dirty forever
|
|
1668
|
+
# never reaches a status call that would read as dirty forever.
|
|
1671
1669
|
if [ -x "$wt" ] && [ ! -f "$wt/.git" ]; then
|
|
1672
1670
|
keep "" "worktree $wt has no .git linkage — git would answer for the enclosing repo, not this one"
|
|
1673
1671
|
continue
|
|
@@ -1676,7 +1674,7 @@ else
|
|
|
1676
1674
|
keep "" "worktree $wt $lk_why"
|
|
1677
1675
|
continue
|
|
1678
1676
|
fi
|
|
1679
|
-
# `-uall`:
|
|
1677
|
+
# `-uall`: see the branch sweep's copy of this probe above for the
|
|
1680
1678
|
# full explanation. This sweep removes DIRECTORIES, so it is the arm
|
|
1681
1679
|
# where the misread a bare `--porcelain` produces costs the files
|
|
1682
1680
|
# themselves.
|
|
@@ -1729,12 +1727,11 @@ else
|
|
|
1729
1727
|
# difference here is that there is no branch to keep with the directory.
|
|
1730
1728
|
# After the ownership bound above, deliberately: a worktree this sweep would
|
|
1731
1729
|
# never remove needs no word about where the script is standing, and the
|
|
1732
|
-
# bound's own reason is the one true of it.
|
|
1730
|
+
# bound's own reason is the one true of it.
|
|
1733
1731
|
#
|
|
1734
1732
|
# Ancestor match, not exact equality — same reasoning as the branch
|
|
1735
1733
|
# sweep's copy of this guard: a worktree nested inside `$wt` is removed
|
|
1736
1734
|
# along with it even though `$wt` never equals `$self_wt` in that shape.
|
|
1737
|
-
# (#1441)
|
|
1738
1735
|
if holds_cwd "$wt"; then
|
|
1739
1736
|
keep "" "worktree $wt holds the working directory this run was started in — removing it would delete the cwd every git call after it needs; rerun from outside it"
|
|
1740
1737
|
continue
|
|
@@ -1751,14 +1748,13 @@ else
|
|
|
1751
1748
|
# `keep "$b"` names the subject, here the branch field is `null` and
|
|
1752
1749
|
# git's own message for a locked worktree carries no path, so two
|
|
1753
1750
|
# refusals in one run were byte-identical and an operator could not tell
|
|
1754
|
-
# which worktree was kept (measured,
|
|
1755
|
-
# worktrees).
|
|
1751
|
+
# which worktree was kept (measured, two locked worktrees).
|
|
1756
1752
|
keep "" "worktree $wt remove refused ($state): $(printf '%s' "$err" | tr '\n' ' ')"
|
|
1757
1753
|
continue
|
|
1758
1754
|
fi
|
|
1759
1755
|
# A line of its own, unlike the branch sweep's silent success: there is no
|
|
1760
1756
|
# `REAPED <branch>` here to stand in for it, and a removal nothing prints
|
|
1761
|
-
# is the silence this
|
|
1757
|
+
# is the silence this sweep exists to end.
|
|
1762
1758
|
printf ' REMOVED worktree %s\n' "$wt" >&2
|
|
1763
1759
|
else
|
|
1764
1760
|
printf ' would remove worktree %s\n' "$wt" >&2
|
|
@@ -1804,7 +1800,7 @@ $broken
|
|
|
1804
1800
|
EOF
|
|
1805
1801
|
fi
|
|
1806
1802
|
|
|
1807
|
-
# Payload first, prune after
|
|
1803
|
+
# Payload first, prune after: `git worktree prune` used to be the last
|
|
1808
1804
|
# command of the guard below — an AND-OR list then — so under `set -eu` ITS
|
|
1809
1805
|
# OWN failure, not just a false `[ apply = true ]`, reached -e and aborted the
|
|
1810
1806
|
# script before this printf ever ran, after the branches above were already
|
|
@@ -1824,12 +1820,12 @@ printf '{"applied":%s,"reaped":[%s],"worktreesRemoved":[%s],"kept":[%s],"warning
|
|
|
1824
1820
|
# Captured, and quoted into the refusal the way `cherry probe failed` and
|
|
1825
1821
|
# `worktree remove refused` above already are: bare, this printed a step name
|
|
1826
1822
|
# and dropped git's stdout and stderr on the floor, so the operator read
|
|
1827
|
-
# `git worktree prune failed` and nothing about what git said (the class
|
|
1828
|
-
#
|
|
1823
|
+
# `git worktree prune failed` and nothing about what git said (the class the
|
|
1824
|
+
# other sites here were already fixed for). Folded to one line by the same
|
|
1829
1825
|
# `tr '\n' ' '` every reason here uses, so one failure stays one line. A
|
|
1830
1826
|
# non-zero exit from this command now means the housekeeping genuinely failed:
|
|
1831
1827
|
# the run standing in a worktree it was about to remove is refused above,
|
|
1832
|
-
# before any removal, rather than diagnosed here afterwards.
|
|
1828
|
+
# before any removal, rather than diagnosed here afterwards.
|
|
1833
1829
|
if [ "$apply" = true ]; then
|
|
1834
1830
|
if ! prune_err=$(git worktree prune 2>&1); then
|
|
1835
1831
|
die "git worktree prune failed: $(printf '%s' "$prune_err" | tr '\n' ' ')"
|