wt remove silently fails on worktrees containing submodules
Summary
wt remove <worktree> -D silently fails when the worktree contains git submodules. The underlying git worktree remove error is swallowed and not shown to the user, making it impossible to understand why the removal failed.
Steps to reproduce
- Have a repository that uses git submodules
- Create a worktree:
wt create feature/my-branch - Try to remove it:
wt remove <worktree> -D
Expected behavior
Either:
- Ideal:
wt removehandles submodules gracefully (e.g., by deinitializing them before removal, or using--force) - Minimum: The underlying git error is surfaced to the user:
fatal: working trees containing submodules cannot be moved or removed
Actual behavior
- The worktree is not removed
- No error message is displayed — the command appears to succeed silently
Running git worktree remove directly on the same path reveals the actual error:
$ git worktree remove /path/to/worktree
fatal: working trees containing submodules cannot be moved or removed
Environment
- worktrunk version: 0.25.0
- OS: Linux (Ubuntu)
- Git version: recent (supports worktrees)
Suggestion
At a minimum, the stderr from git worktree remove should be forwarded to the user. Ideally, wt remove could detect the submodule situation and either:
- Automatically handle it (e.g.,
git submodule deinit --allbefore removal, or fallback torm -rf+git worktree prune) - Provide a helpful error message suggesting a workaround
Thanks for reporting this! I was able to reproduce the issue and identified the root cause: git worktree remove refuses to remove worktrees with initialized submodules unless --force is passed, and wt remove wasn't handling this case.
I've opened #1196 with a fix that automatically retries with --force when the submodule error is detected (safe because worktree cleanliness is already validated beforehand). A maintainer will review it shortly.
Thanks for the quick turnaround! The approach of retrying with --force when the submodule error is detected sounds good to me — it's safe since worktree cleanliness is already validated beforehand. Looking forward to the fix landing.
Thank you @max-sixty