[Fix] Add --pr-aware flag to prune and fix dirty worktree detection#61
Merged
[Fix] Add --pr-aware flag to prune and fix dirty worktree detection#61
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a --pr-aware flag to the worktree prune command, enabling the tool to verify GitHub PR statuses via the gh CLI before deleting worktrees. The implementation refactors the pruning logic into distinct strategies and adds a tabular report for better visibility. Review feedback recommends increasing the PR list limit for larger repositories and passing the report structure by pointer to ensure idiomatic consistency and avoid value-copying bugs.
GetWorktreeStatus returns detailed strings like '1 file changed' or '1 untracked', never the literal 'modified'. The previous equality check status == "modified" never matched, silently skipping the dirty worktree protection. Compare against 'clean' instead. Signed-off-by: samzong <samzong.lu@gmail.com>
Add PR-aware pruning that checks GitHub PR state via gh CLI before deciding whether to remove a worktree. This internalizes the logic from skill/scripts/wt-cleanup.sh as native Go code. Key design decisions: - Single batch gh pr list call (not N+1 per branch) - ghRunFunc seam for testability without real gh binary - Report.PruneEntries carries structured data (no side-channel) - Shared collectPruneCandidates eliminates classic/pr-aware duplication - strings.ToUpper normalizes PR state for case-insensitive matching Decision matrix for --pr-aware: - MERGED + clean → remove (or would_remove with --dry-run) - MERGED + dirty → skip (unless --force) - CLOSED → skip (PR closed, not merged) - OPEN → skip (PR still open) - No PR → skip Closes #53 Signed-off-by: samzong <samzong.lu@gmail.com>
ef619d0 to
fae2c40
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
--pr-awareflag togmc wt prunethat checks GitHub PR state viaghCLI before deciding whether to remove a worktreegh pr listcall (not N+1 per branch) with local map lookupPruneEntryoutput with table display (NAME, BRANCH, PR, PR STATE, ACTION, REASON)ghRunFuncseam for testability without realghbinarycollectPruneCandidateseliminates duplication between classic and PR-aware pathsstatus == "modified"never matched (GetWorktreeStatusreturns detailed strings like1 file changed). Changed tostatus != "clean".Why
skill/scripts/wt-cleanup.shas native Go, eliminating the python3 dependencyCloses #53