worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

wt remove silently fails on worktrees containing submodules

Open dlecan opened this issue 9 months ago • 3 comments

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

  1. Have a repository that uses git submodules
  2. Create a worktree: wt create feature/my-branch
  3. Try to remove it: wt remove <worktree> -D

Expected behavior

Either:

  1. Ideal: wt remove handles submodules gracefully (e.g., by deinitializing them before removal, or using --force)
  2. 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 --all before removal, or fallback to rm -rf + git worktree prune)
  • Provide a helpful error message suggesting a workaround

dlecan avatar Feb 25 '26 07:02 dlecan

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.

worktrunk-bot avatar Feb 25 '26 08:02 worktrunk-bot

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.

dlecan avatar Feb 25 '26 09:02 dlecan

Thank you @max-sixty

dlecan avatar Feb 27 '26 11:02 dlecan