Skip to content

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
fix/clean-tolerates-deleted-branchesfrom
fix/prune-stale-remote-refs
Open

fix: prune stale tracking refs before pushing so re-split branches are not rejected as stale#157
vitali87 wants to merge 1 commit into
fix/clean-tolerates-deleted-branchesfrom
fix/prune-stale-remote-refs

Conversation

@vitali87

Copy link
Copy Markdown
Owner

Summary

Split branch names are reused across runs (pr-split/<ns>/<group>). After pr-split merge (gh deletes the head branch), clean, or GitHub auto-deleting head branches, the remote branch is gone but refs/remotes/origin/pr-split/… still points at the old head — so every git push --force-with-lease of the next split was rejected with "stale info", PRCreationError fired, and the plan was saved with branches but no PRs. Re-splitting the same dev branch was impossible without a manual git fetch --prune.

  • _push_and_create_prs now runs git remote prune origin once before the push pool (warning-only if origin is unreachable). It drops only refs whose remote branch is gone — deliberately not fetch --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) drops refs/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

  • real-git 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 it
  • TestPushPrunesFirst (prune before any push); mocked delete_branch tests stub the helper
  • Review re-ran its probe (third-party push, deleted branch, single-branch clone, unreachable origin)
  • 464 tests pass, ruff clean
  • Local review: 5/5 (after one fix→re-review round)

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e9599bf5-ffdf-477d-ab08-a07f62530de5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vitali87
vitali87 force-pushed the fix/prune-stale-remote-refs branch from e2495a9 to 72fb0aa Compare August 30, 2026 19:24
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