fix: make branch cleanup reliable on failure and in clean - #55
Conversation
|
Warning Review limit reachedNext included review available in 39 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis change expands cleanup for failed branch creation and retains the saved plan when cleanup is incomplete. Reproduction found that failed branch setup can delete a branch that existed before the command started, and that cleanup retries can remain incomplete after remote branches were already deleted because completion is neither persisted nor treated idempotently. Confidence Score: 3/5Not safe to merge until failed branch cleanup preserves pre-existing branches and cleanup retries can recognize resources already removed. Two independent reproduced failures affect destructive branch handling and cleanup completion. Both were exercised with isolated runtime harnesses and captured outputs. Files Needing Attention: pr_split/cli.py needs changes around failed-group branch cleanup and retry accounting; pr_split/git_ops/branches.py should be considered when making remote deletion idempotent.
What T-Rex did
|
aece25d to
247c028
Compare
- A group that failed after add_worktree left its branch behind because only successful groups were cleaned up; delete failed groups' branches too - delete_branch(remote=True) skipped the remote deletion when the local branch could not be deleted (checked out, or already removed); always attempt the remote deletion and re-raise the local error afterwards - clean removed plan.json even when some PRs or branches could not be cleaned up, losing the records needed to retry; keep the plan and exit non-zero when cleanup is incomplete
Move the failed-group branch deletion into the worker, after add_worktree has succeeded. If add_worktree itself fails it restores any pre-existing branch of that name, and that branch must not be removed.
247c028 to
1f73aa3
Compare
Summary
Three related cleanup gaps found by review:
add_worktreecreates the branch before the commit step, but the failure path in_create_branches_and_commitsonly deleted branches of successful groups. Reproduced: afterpr-2failed,git branch --list 'pr-split/*'still showedpr-split/ns/pr-2. Now the failed groups' branches are deleted as well (silently, sinceadd_worktreeitself may have been the failure).delete_branch(remote=True)skipped the remote. Ifgit branch -Dfailed (branch checked out to inspect CI, or already removed bymerge --delete-branch), thegit push origin --deletenever ran. Now the remote deletion is always attempted and the local error re-raised afterwards.cleandiscarded the plan on partial failure.plan.jsonwas unlinked unconditionally, so an orphaned remote branch or PR record was lost. Now the plan is kept when any PR/branch could not be cleaned,cleanprints why and exits 1 so it can be re-run.Test plan
remoteraises immediately; partial cleanup keeps the planuv run ruff check/ruff format --checkcleanuv run pytest -q— 447 passed