Skip to content

feat: wt delete takes more than one worktree - #9

Merged
lorenzolfm merged 2 commits into
mainfrom
delete-many-worktrees
Oct 19, 2026
Merged

lorenzolfm merged 2 commits into
mainfrom
delete-many-worktrees

Conversation

@lorenzolfm

@lorenzolfm lorenzolfm commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

wt delete took one worktree. It now takes several: wt d a b c.

  • The command finds each name before it removes anything, so a name that is wrong changes nothing. The error gives each name that is wrong, so the user can correct the list in one step.
  • Git can refuse a worktree that has a modified or untracked file. The command then keeps that worktree, removes the others and fails at the end with the names that it kept. --force applies to each worktree.
  • The message for a refusal says "use --force to remove it", or "them" for more than one worktree. With --force it gives no hint, because git refused for a different reason, for example a lock.
  • A worktree that has two names in the list, its directory and its path, is removed one time.

The fish completion already offers the worktrees for each argument after wt d. Only its description changes.

The git helper for the test fixtures moves from the tests of wt add to src/testing.rs, so the tests of wt add and wt delete share it.

Test

Format check, clippy and cargo test pass. Three new tests run wt delete in a temporary repository:

  • A list with two wrong names gives both names, and no worktree is removed.
  • A worktree with its directory and its path in the list is removed one time.
  • A worktree with an untracked file is kept, and the worktrees before and after it are removed.

Each test fails when the behavior that it protects is removed from the code.

A manual test in a temporary repository with the worktrees a b c d and an untracked file in c:

Command Result
wt d a typo b Error with the list of names. Nothing removed.
wt d typo a other Error that gives typo and other. Nothing removed.
wt d a b c a a and b removed. c kept, exit 1.
wt d c d --force c and d removed.
wt d Usage error.

With a locked worktree l, wt d l d --force removes d, keeps l and fails with wt cannot remove l, with no hint to use --force.

wt delete took one worktree. Remove several worktrees in one command:
`wt d a b c`.

The command finds each name before it removes anything, so a name that is
wrong changes nothing. Git can refuse a worktree that has a modified or
untracked file. The command then keeps that worktree, removes the others
and fails at the end with the names that it kept. A worktree that has two
names in the list, its directory and its path, is removed one time.
The error for a wrong name gave only the first one, so a list with two
typos took two runs to correct. It now gives each wrong name.

The message for a refusal said "use --force to remove it" also for two
worktrees, and also when --force was on. It now says "them" for more
than one worktree. With --force it gives no hint, because git refused
for a different reason, for example a lock.

Three tests run the command in a temporary repository: a wrong name
changes nothing, a worktree with two names in the list is removed one
time, and a refusal keeps that worktree and removes the others. The git
helper for the fixtures moves from the tests of `wt add` to
src/testing.rs, so the two modules share it.
@lorenzolfm
lorenzolfm merged commit 3848184 into main Oct 19, 2026
4 checks passed
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