-
Notifications
You must be signed in to change notification settings - Fork 0
wt-destroy fails for nested worktree paths and merged branches #38
Description
Problem
just wt-destroy has two issues that cause it to fail in common workflows:
1. Nested paths are truncated by basename
The recipe does BRANCH="$(basename "{{ target }}")", which strips directory prefixes. When a worktree was created with a path like fix/discovery-dual-style, the worktree is registered under that full path, but basename reduces it to just discovery-dual-style. Then git worktree remove "discovery-dual-style" fails with:
fatal: 'discovery-dual-style' is not a working tree
2. No --force flag for merged branches
After a branch is merged and the PR closed, the worktree often contains untracked files (build artifacts, .env, etc). git worktree remove without --force refuses to delete it:
fatal: 'discovery-dual-style' contains modified or untracked files, use --force to delete it
Since wt-destroy is explicitly a destructive "nuke it" command (it also deletes the remote branch), it should use --force.
Suggested fix
wt-destroy target:
#!/bin/bash
set -euo pipefail
# Use the target as-is for worktree removal (preserves nested paths)
git worktree remove "{{ target }}" --force
# Determine the branch name from the worktree's tracking branch
BRANCH="$(git -C "{{ target }}" rev-parse --abbrev-ref HEAD 2>/dev/null || basename "{{ target }}")"
# ... rest of recipe using $BRANCH for branch deletionOr alternatively, just pass the target through to git worktree remove without basename, and use --force since this is the destructive variant (vs wt-rm which is the safe one).
Reproduction
just wt-add fix/my-feature
# ... do work, merge PR ...
just wt-destroy fix/my-feature # fails with both issuesWorkaround
git worktree remove fix/my-feature --force
git branch -D fix-my-feature
git push origin --delete fix-my-feature