Tags: Jercik/worktree-remove
Tags
feat: support removing multiple worktrees at once (#19) * feat: support removing multiple worktrees at once Add multi-select to both interactive and non-interactive modes: - CLI argument changes from [target] to variadic [target...] - Interactive mode uses checkbox (multi-select) instead of single select - Batch path resolves all targets upfront, checks uncommitted changes once, confirms in a single prompt, then removes in parallel (p-limit) - Single target still uses the existing removeWorktree flow * fix: return result from performWorktreeRemoval to fix batch success accounting performWorktreeRemoval has failure paths that return without throwing, causing Promise.allSettled to count them as fulfilled. The batch summary would over-report success (e.g. "Removed 2 of 2" when one failed). Return { ok: boolean } so removeBatch can accurately track outcomes. * refactor: unify single-target and batch removal into one code path Route all targets through removeBatch, eliminating the duplicated resolution/preflight logic in removeWorktree. The batch path now handles n=1 with appropriate singular grammar and compact confirmation prompts. Delete remove-worktree.ts entirely. Extract cwd-switch detection and handling into handle-cwd-switch.ts to keep remove-batch.ts within complexity thresholds. * fix: address review feedback on batch removal - Return ok:false from performWorktreeRemoval when git unregister fails - Force-skip internal prompts in multi-target batch (prevents concurrent readline races since user already confirmed in Phase 2) - Use "Would remove" instead of "Removed" in dry-run summary - Log explicit failure line for fulfilled-but-not-ok results - Deduplicate targets by normalized path before processing * fix: correct cwd warning target name and unregister failure reporting - prepareCwdSwitch now finds the actual target containing cwd instead of always using the first target's name - performWorktreeRemoval returns ok:false when git unregister fails - Multi-target batch passes force:true to skip internal prompts - Dry-run summary uses "Would remove" wording - Batch summary logs explicit failure for fulfilled-but-not-ok results * fix: decouple prompt suppression from force flag in batch removal Add `skipTrashFailurePrompt` to `performWorktreeRemoval` so batch mode can prevent concurrent readline races without also enabling destructive fallback when trash fails. Multi-target batches now report trash failures as errors instead of silently proceeding with `git worktree remove --force`. Also error when all batch targets resolve to empty instead of silently returning success (regression from the single-target path). * fix: exit with code 1 for single-target removal failures Single-target failures now exit with code 1, matching multi-target behavior. Previously, single-target mode skipped Phase 4 entirely, causing performWorktreeRemoval failures to silently exit 0. * fix: distinguish user cancellation from failure in removal result Use a discriminated union (status: "ok" | "failed" | "cancelled") for PerformWorktreeRemovalResult instead of a boolean. Single-target user cancellation (declining the trash-failure prompt) now exits cleanly with code 0 instead of being misreported as a failure with code 1. * docs: clarify fail-fast resolution in batch target loop Add comment explaining why resolution exits immediately on invalid targets — it runs before confirmation or removal, so no worktrees are modified yet. * fix: prefix per-target output in multi-target verbose/dry-run mode Wrap the OutputWriter with target-name prefixes (e.g., [foo] Moving directory to trash...) for multi-target batches so interleaved parallel output is attributable. Single-target mode is unchanged. Extract prefixOutput into output-writer.ts and batch result reporting into report-batch-results.ts to keep remove-batch.ts under the FTA complexity threshold.
fix: handle detached HEAD worktrees (#15) * fix: handle detached HEAD worktrees * fix: harden target resolution * test: clarify detached parsing * fix: normalize worktree paths on Windows * fix: harden path matching and safety * fix: warn when interactive ignores target * fix: prevent root directory removal * fix: parse worktree list -z output * fix: improve path matching fallbacks * fix: tighten safety and parsing * fix: improve trash flow and docs * fix: align cli behavior with unix conventions * fix: remove redundant readme reference from AGENTS.md * fix: tighten removal prompts and docs * fix: exit early after trash failure * fix: refine removal safety controls * fix: align confirmations and force retry * docs: clarify path target scope * fix: propagate force flag on trash failure and fix detached label When trash fails and the user confirms proceeding, force the unregister so git worktree remove can handle dirty worktrees. Drive the select-worktree label off isDetached instead of inferring from HEAD presence, preventing bare worktrees from being mislabeled as detached. * fix: surface trash failure reason in user-facing messages Return the error reason from trashDirectory instead of a bare boolean, and include it in confirmation prompts and warnings so users can diagnose why trash failed. * docs: clarify cross-platform absolute path detection * fix: surface unregister failure reason in user-facing messages Return an actionable reason from unregisterWorktree when git worktree remove fails due to local modifications, so the caller can tell the user to re-run with --force instead of showing a generic warning. * fix: propagate all unregister error reasons and add display tests Always include the error reason in UnregisterResult (no more undefined), so unknown git errors surface to the user instead of being silently swallowed. Add tests for getRemovalDisplayInfo covering status values, branch/detached reference info, and path display logic. * fix: propagate isPathInput for registered worktree targets Add isPathInput to the registered variant of ResolvedWorktreeTarget so path-based inputs that resolve to registered worktrees display the full target path instead of a potentially confusing relative path. * fix: use error level for operational failures in quiet mode Upgrade partial failure messages (trash failure, unregister failure, directory still exists) from warn to error so they remain visible even with --quiet.
feat: display path alongside branch in worktree list (#14) * feat: display path alongside branch in worktree list Show relative path next to branch name in the interactive worktree selection, making it easier to identify which worktree to remove. * feat: sort worktree list alphabetically by branch name Makes it easier to find a specific worktree when there are many. Also updates TypeScript lib to es2023 for toSorted() support.