Skip to content

Conversation

@timvw
Copy link
Owner

@timvw timvw commented Jan 26, 2026

Summary

  • Add new wt cleanup command that identifies and removes worktrees for merged branches
  • Support --dry-run flag to preview what would be removed
  • Support --force flag to remove all without interactive confirmation
  • Default mode prompts for confirmation on each worktree
  • Automatically runs git worktree prune after cleanup

Usage

# Preview what would be removed
wt cleanup --dry-run

# Remove all merged worktrees without prompting
wt cleanup --force

# Interactive mode (default) - confirm each removal
wt cleanup

Why

After merging feature branches, worktrees often accumulate. This command provides a built-in alternative to manual cleanup scripts, making it easier to keep worktree directories tidy.

Testing

  • Added unit tests for getMergedBranches helper function
  • Added E2E test that creates a temporary repo with a merged branch worktree and verifies cleanup works correctly
  • All existing tests pass

Add a new 'wt cleanup' command that identifies worktrees associated with
branches that have been merged into main/master and removes them.

Features:
- --dry-run: Preview what would be removed without making changes
- --force: Remove all merged worktrees without interactive confirmation
- Default: Interactive confirmation for each worktree
- Automatically runs 'git worktree prune' after cleanup

This provides a built-in alternative to manual cleanup scripts, making
it easier to keep worktree directories tidy after merging feature branches.
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 63.38028% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.78%. Comparing base (01d5f7f) to head (0988384).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
main.go 63.38% 19 Missing and 7 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   17.64%   22.78%   +5.14%     
==========================================
  Files           3        3              
  Lines         958     1027      +69     
==========================================
+ Hits          169      234      +65     
+ Misses        767      759       -8     
- Partials       22       34      +12     
Files with missing lines Coverage Δ
main.go 28.54% <63.38%> (+9.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add declarative E2E test scenarios for the cleanup command:
- cleanup_dry_run_shows_merged: Verify dry-run shows merged branch worktrees
- cleanup_dry_run_preserves_worktrees: Verify dry-run doesn't remove anything
- cleanup_force_removes_merged: Verify --force removes merged worktrees
- cleanup_no_merged_branches: Verify graceful handling when nothing to clean
- cleanup_cleans_directory: Verify filesystem cleanup

Also update AGENTS.md with documentation about the YAML E2E test framework
to help future AI agents understand the testing approach.
@timvw timvw merged commit ad02504 into main Jan 26, 2026
11 checks passed
@timvw timvw deleted the feat/cleanup-command branch January 26, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants