mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
git worktree remove deletes the checkout first and the metadata dir second. Under the agent sandbox, which holds config.worktree and commondir as read-only bind mounts, it therefore dies with EBUSY after the checkout is already gone, aborting make worktree-down with rc 255 even though the branch is in fact free. down.sh now falls back to the unregistration prune.sh already used (drop gitdir + HEAD, best-effort rm -rf) and reports any dir the sandbox still pins. That routine moves into lib.sh so both callers cannot drift apart, and gains a third outcome for the case where gitdir/HEAD themselves survive: only then is the branch still claimed, and only then must the teardown fail. The discriminator for the fallback is whether the checkout survived, not a match on "Device or resource busy" — the identical half-removed state arises from EACCES, EPERM and EROFS. A failing git status probe no longer reads as clean: on a broken .git link it exits 128 with empty output, which used to satisfy the guard, tear down the compose stack, and only then die at git worktree remove with an unexplained 128. Measured against the unfixed scripts with real fixtures: pinned metadata dir 255 -> 0, broken .git link 128 -> 1. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>