Skip to content

Comments

feat: add wt.remover config and --remover flag#144

Merged
k1LoW merged 2 commits intok1LoW:mainfrom
ryoppippi:feat/add-remover
Feb 16, 2026
Merged

feat: add wt.remover config and --remover flag#144
k1LoW merged 2 commits intok1LoW:mainfrom
ryoppippi:feat/add-remover

Conversation

@ryoppippi
Copy link
Contributor

Summary

  • Add wt.remover config key and --remover CLI flag to replace git worktree remove with a custom command (e.g. trash-put)
  • After the custom remover runs, git worktree prune cleans up git's internal tracking automatically
  • Worktree path is passed safely via shell positional argument ("$1") to handle spaces and special characters

Motivation

git worktree remove uses rm -rf internally, which can be slow for large worktrees. Trash commands like trash-put move directories to the system trash instantly, providing a much faster alternative.

Usage

# Persistent via git config
git config wt.remover "trash-put"

# One-off via flag
git wt -D --remover "trash-put" my-branch

Files Changed

  • internal/git/config.go: Added configKeyRemover constant, Remover field to Config, loading logic in LoadConfig()
  • internal/git/worktree.go: Added RunRemover() and PruneWorktrees() functions
  • cmd/root.go: Added --remover flag, flag override in loadConfig(), remover branch in deleteWorktrees(), help text
  • e2e/config_test.go: Added TestE2E_Remover with 6 subtests, updated completion flag list

Test Plan

  • go build ./... compiles cleanly
  • go vet ./... passes
  • 6 new e2e subtests pass: flag, config, flag_overrides_config, failure_prevents_deletion, prune_cleans_up, path_with_spaces
  • TestE2E_Complete passes with --remover in expected flags

Closes #143

Add support for a custom worktree removal command that replaces
`git worktree remove`. When `wt.remover` is set (via config or
`--remover` flag), the specified command receives the worktree path
as an argument and is used instead of the default removal. After
the custom command completes, `git worktree prune` runs automatically
to clean up git's internal worktree tracking.

This is useful for faster deletion via trash commands (e.g. trash-put)
which move directories to the system trash instantly rather than
performing a recursive delete.

The worktree path is passed safely as a shell positional argument
(`"$1"`) to handle paths containing spaces or special characters.

Closes k1LoW#143
# Conflicts:
#	cmd/root.go
#	e2e/config_test.go
#	internal/git/config.go
@k1LoW k1LoW added enhancement New feature or request tagpr:minor labels Feb 16, 2026
@ryoppippi
Copy link
Contributor Author

why we need this.
rm -rf is slow for large monorepo(usually nodemodule can be 10GB)
so i want to use trash command or mv /tmp/ instead

Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great!!

@k1LoW k1LoW merged commit 4af4773 into k1LoW:main Feb 16, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tagpr:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support custom worktree removal command (e.g. trash-cli)

2 participants