fix: prune stale tracking refs before pushing so re-split branches are not rejected as stale - #157
Open
vitali87 wants to merge 1 commit into
Open
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
…e not rejected as stale
vitali87
force-pushed
the
fix/prune-stale-remote-refs
branch
from
August 30, 2026 19:24
e2495a9 to
72fb0aa
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.
Summary
Split branch names are reused across runs (
pr-split/<ns>/<group>). Afterpr-split merge(gh deletes the head branch),clean, or GitHub auto-deleting head branches, the remote branch is gone butrefs/remotes/origin/pr-split/…still points at the old head — so everygit push --force-with-leaseof the next split was rejected with "stale info",PRCreationErrorfired, and the plan was saved with branches but no PRs. Re-splitting the same dev branch was impossible without a manualgit fetch --prune._push_and_create_prsnow runsgit remote prune originonce before the push pool (warning-only if origin is unreachable). It drops only refs whose remote branch is gone — deliberately notfetch --prune, which would refresh live refs and silently defeat the lease against a reviewer's fixup push to a reused branch (the review caught that in the first version).delete_branch(remote=True)dropsrefs/remotes/origin/<branch>after the remote delete, covering the "already gone on origin" case.Stacked on #156 (stack #152 = #55→#151→#156→this).
Test plan
TestStaleRemoteTrackingRefs: remote branch deleted behind our back → push rejected as stale → prune → push succeeds; a third-party fixup push is still rejected after prune (lease intact); remote delete drops the tracking ref; already-deleted remote still drops itTestPushPrunesFirst(prune before any push); mockeddelete_branchtests stub the helper