Skip to content

feat: add tidy command for branch cleanup - #342

Open
bkrupa wants to merge 4 commits into
mainfrom
feature/tidy-command
Open

feat: add tidy command for branch cleanup#342
bkrupa wants to merge 4 commits into
mainfrom
feature/tidy-command

Conversation

@bkrupa

@bkrupa bkrupa commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

New twig tidy command for cleaning up branches:

  1. tidy clean - Remove local branches that have been merged or deleted on remote
  2. tidy prune - Prune stale remote-tracking references

Provides a safe, interactive workflow for branch cleanup with preview before deletion.

Files changed

  • twig-cli/src/cli/tidy.rs (new) - Tidy command implementation
  • twig-cli/src/cli/mod.rs - Command registration

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @bkrupa, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

- Add twig tidy clean: remove branches with no unique commits
- Add twig tidy prune: remove stale branch references from twig config
- Support --dry-run, --force, and --aggressive modes
- Aggressive mode reparents children before deleting empty intermediates
- Issue #1 (MAJOR): fix detached/unborn HEAD crash in is_current_branch by
  using match instead of ? propagation
- Issue #2 (MAJOR): guard has_non_cleanable_children against dependency
  cycles with a visited HashSet to prevent stack overflow
- Issue #3 (MAJOR): move reparenting discovery to a pre-pass so the full
  deletion list (including reparenting-triggered deletions) is shown to
  the user before confirmation
- Issue #4 (MAJOR): fix find_reparenting_opportunities to group by unique
  intermediate branch, preventing conflicting ops when the same branch
  appears as parent in multiple dependencies
- Issue #5 (MINOR): collapse nested if statements (clippy::collapsible_if)
- Issue #6 (MINOR): extract prompt_for_confirmation to crate::utils and
  share it across adopt.rs and tidy.rs
- Issue #7 (MINOR): remove inline use std::io imports from function bodies
- Issue #8 (MINOR): gate hardcoded fallback parents (main/master/develop)
  behind --aggressive mode via with_fallback parameter
- Issue #9 (MINOR): cleanup_branch_from_config now also removes
  repo_state.branches metadata to stay consistent with prune
- Issue #10 (MINOR): add 8 integration tests covering has_unique_commits,
  detached HEAD, cleanup metadata, fallback parent behaviour, cycle guard,
  and conflicting reparenting ops
- Issue #11 (NIT): add Rustdoc to TidyArgs fields
- Issue #12 (NIT): change find_cleanable_dependency_chain to return
  Option<Vec<String>> for clearer semantics
- Issue #13 (NIT): use HashSet for O(1) dedup checks on branches_to_delete
- Issue #14 (NIT): fix contradictory comment about non-interactive mode

Also fix pre-existing clippy::useless_format lint in windows.rs
@bkrupa
bkrupa force-pushed the feature/tidy-command branch from 4972c41 to f06a45d Compare February 26, 2026 00:52
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.

1 participant