Skip to content

Let Delete worktree warn and offer choices instead of blocking - #224

Merged
yansfil merged 4 commits into
mainfrom
fix/worktree-delete-options
Sep 28, 2026
Merged

yansfil merged 4 commits into
mainfrom
fix/worktree-delete-options

Conversation

@yansfil

@yansfil yansfil commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Delete worktree… was disabled whenever a worktree was dirty, held a nested worktree, sat on the base branch, could not be read, or lived on another device, so the operator had to leave hide to clean up.
The item is now always enabled on a linked worktree, and the dialog shows what would be lost and lets the operator choose.
The core gate refuses only the main worktree. Everything else is a warning.
Also delete branch uses git branch -d when the branch is merged and -D (with the commit count) when it is not.
A required Discard … checkbox removes a dirty or nested worktree with git worktree remove --force.
One line names every agent the closing panes stop, and each refusal or failure appears in the dialog with the choices offered again.

Dirty worktree with an unmerged branch and an agent: Delete stays disabled until Discard is ticked

Review

  • Needs your judgment: branch deletion is not offered for the base-branch worktree or a missing folder, even though the worktree itself can go.
  • Needs your judgment: an unreadable Git status also shows a required Discard any uncommitted changes, and a branch whose merge state Git cannot tell is deleted with -D under a warning.
  • Needs your judgment: the agent line lists every pane with an agent and its state (Idle included), not only working ones, because all of them are stopped.
  • Files to watch: hide-host/src/worktrees.rs (failure path, destructive): discard_changes skips the dirt, nested-worktree and ignored-repository rechecks and adds --force.
  • Files to watch: herdr-core/src/runtime/projects.rs (runtime mutex): worktree_removal_allowed refuses a discard the current row needs but the payload did not accept. protected_base_branch is dropped only for a worktree already on the base.
  • Files to watch: scripts/check-worktree-removal-boundary.sh (gate changed): it forbade any -D or --force, which is the policy the operator reversed. It now requires each force to be tied to the recorded choice (discard_changes, force_delete_branch), and still forbids any force in the Overview cleanup.
  • Files to watch: hide-host/src/worktrees.rs ConfirmedRemoval (device protocol): the new fields are #[serde(default)], so an older device helper does the safe non-force removal.

Evidence

  • Confirmed: native Electron dev app over an isolated Herdr, with a real dirty worktree (3 files, 2 unmerged commits) and an agent. The dialog blocks until Discard is ticked, and with both boxes ticked the folder and branch are gone (captures below).
  • Confirmed: new e2e e2e/worktree-delete.spec.ts covers the same flow and checks the row leaves, the folder is gone and the branch is deleted. e2e/sidebar-menus.spec.ts passes.
  • Confirmed: new host tests cover force removal of a dirty worktree with -D, -d keeping an unmerged branch under discard, a nested worktree removed only with discard, and late dirt refused with the new plain message.
  • Confirmed: a device runtime test covers a dirty device worktree refused as worktree.remove_unaccepted without discard, then removed by the device helper with -D once accepted.
  • Confirmed: verify-cargo.sh test -p herdr-core -p hide-host (909 core tests), verify-cargo.sh lint and verify-web.sh all pass.
  • Not confirmed: late dirt after confirmation (an agent writing while it stops) was not triggered in the live app. Only host tests cover it.
  • Not confirmed: no live remote-device deletion was run. The device path is covered by the runtime test with an in-process helper.
  • Not confirmed: the Pen library's Delete worktree dialog sheet was not redrawn for the new checkboxes.
More evidence

Both boxes ticked: the branch warning names the unmerged commits

After deletion: the dialog reports the folder and branch removed

Review follow-ups not taken in this PR: show a locked worktree as its own warning instead of Git's raw refusal, and mention ignored nested repositories in the Discard copy.

AI tooling: mostly AI tooling; the dialog states, warnings and removal outcomes were checked by hand against the native captures and test assertions.

The deletion gate now refuses only the main worktree. Dirt, a nested
worktree, the base branch and an unreadable status become warnings, and
the dialog offers Also delete branch (-d merged, -D unmerged with the
commit count) and a required Discard checkbox that removes with --force.
The agents the closing panes stop are listed once by name and state, the
menu item is enabled on device rows and before Git is read, and every
refusal or failure is shown in the dialog with the choices offered again.
…choice

The confirmation now offers Discard (--force) and deleting an unmerged
branch (-D), so the invariant checks that each force is tied to that
recorded choice and that the Overview cleanup still never forces.
@yansfil
yansfil merged commit bac8658 into main Sep 28, 2026
7 checks passed
@yansfil
yansfil deleted the fix/worktree-delete-options branch September 28, 2026 04:38
yansfil added a commit that referenced this pull request Sep 28, 2026
…every project (#228)

Related: #224 (the dialog options this builds on)

## Summary

After confirming `Delete worktree…`, the sidebar row looked untouched,
and it stayed after the dialog said "Deleted" until every project's Git
state was re-read.
The row is now dimmed with a spinner from the confirmation, cannot be
opened, and leaves within about a second of the removal finishing.
A finished removal drops its row from the catalog in the same frame;
only the removed repository is read again, not every project.
The host moves the folder aside into the repository's Git directory,
lets `git worktree remove` drop only the registration, and deletes the
files in the background.
Before, a 1.5 GB build folder with 400k files took 38.9 s in `git
worktree remove`, past the 15 s Git read bound that killed it.

![The chore/old-experiment row is dimmed with a spinner while its
worktree is
deleted](https://github.com/yansfil/pr-assets/blob/main/herdr-ide/worktree-delete-latency/aab872e/removing-row.png?raw=true)

## Review

- **Needs your judgment**: the move-aside design. Chosen over a longer
deadline because the row can leave as soon as Git forgets the worktree,
however long the deletion takes.
- **Needs your judgment**: a removed folder waits in `<git common
dir>/hide-removed/` until a background thread deletes it. A leftover
from a stopped process is swept by the next removal in that repository,
not at startup.
- **Needs your judgment**: while removing, the row's context menu opens
nothing (empty), so `Open` and a second `Delete worktree…` are
unreachable.
- **Files to watch**: `hide-host/src/worktrees.rs` (failure path,
destructive): `set_aside` moves only when Git would remove (registered,
not main, not locked, clean unless forced); a refusal moves the folder
back; `sweep_trash` deletes an entry only once Git's admin folder no
longer registers it.
- **Files to watch**: `herdr-core/src/runtime/projects.rs` (runtime
mutex): `drop_removed_worktree` edits the catalog in memory under the
lock; no Git or filesystem work was added there.
- **Files to watch**: `herdr-core/src/session_sync/coordinator.rs`: the
navigator is rebuilt on the 250 ms wake that sees
`WorktreeRequest::removals` move, since the next read may find nothing
new.
- **Files to watch**: `herdr-core/src/worktrees.rs`: `removals` rides
through the reader and back, so a read that started before the removal
cannot bring the row back.

## Evidence

- **Confirmed**: confirm-to-row-gone in the web shell against an
isolated Herdr, 5 cloned projects with 2 extra worktrees each, a real
2.2 GB `target/` copied into the deleted worktree, 3 trials each (load
average 7 to 10).

| | row gone, idle | row gone, driven (commit every 300 ms in another
project) |
  | --- | --- | --- |
  | before (bac8658) | 2.2 / 2.3 / 7.2 s | 9.0 / 9.7 / 9.8 s |
  | after | 0.49 / 0.72 / 1.03 s | 0.82 / 0.87 / 1.02 s |

The dimmed row appears 10 to 23 ms after the confirm click; the dialog's
"finished" arrives at 0.4 to 0.9 s in both builds.
- **Confirmed**: host tests cover a 5,000-file build folder removed by
setting it aside with the trash drained, Git's own dirty and locked
refusals leaving the folder in place, and a stopped-midway entry kept
until a retry drops the registration and deletes it once.
- **Confirmed**: runtime tests cover the row dropped without a global
re-read, an older read unable to restore it, a newer read restoring a
re-created worktree, and a failed removal keeping its row.
- **Confirmed**: `e2e/worktree-delete.spec.ts` now also observes the
dimmed, spinner, disabled row during removal; `verify-cargo.sh test`,
`verify-cargo.sh lint`, `verify-web.sh`, the design contract and the
`scripts` lane checks pass locally.
- **Not confirmed**: not run in the packaged desktop app; the
measurements and screenshots are the web shell served by a dev `hided`.
- **Not confirmed**: the cross-volume fallback (in place, 60 s
`REMOVE_DEADLINE`) has no test; device removals are unchanged and still
re-read the device's catalog.
- **Not confirmed**: a trash entry whose deletion fails (for example a
read-only folder inside it) stays until the next sweep and is only
logged.

<details><summary>More evidence</summary>

![After the removal: the row is gone and the notice reports the
deletion](https://github.com/yansfil/pr-assets/blob/main/herdr-ide/worktree-delete-latency/aab872e/removing-row-after.png?raw=true)

Review follow-ups not taken: a reader-level test that drives a real
in-flight read across a removal, and a note that the clean check and the
rename are two steps (the confirmation rechecks status just before).

</details>

**AI tooling**: mostly AI tooling; the removal states, timings and trash
behavior were checked by hand against the screenshots, measurement
output and test assertions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant