Repository navigation
tools/pr-land.py: restack a stacked branch by merges after the PR below squashes - #1055
Merged
Merged
Conversation
…o not allow gate is the read-only verdict: the PR open, not a draft, on main or release/v*, at the asserted head, every required context of the base's rules reported and passing, nothing pending, failed or cancelled, mergeStateStatus CLEAN (UNKNOWN and an all-green BLOCKED are re-polled; BEHIND and DIRTY say to merge the base into the branch). wait polls it with a 30-60 s backoff, never gh run list. merge is wait, then gh pr merge --squash --match-head-commit (never --auto) with a required body, retrying only the head-oid race, then a verify against origin/<base>. The subject and body go through outbound-guard in-process before any gh call. Exit codes: 0 green, 1 red, 2 usage, 3 refused, 4 timeout, 5 head moved. tools/test_pr_land.py runs it against a fake gh on PATH with an injected sleeper, real gh JSON as fixtures, and a temporary git origin for the verify. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
…s the merge went through UNSTABLE is GitHub's "mergeable with a non-passing commit status": the required checks pass while a non-required one (CodeQL) still runs or failed. It was refused by name as an unknown state, so a merge started in that window exited 3 at once and never waited, and a failing non-required check gave exit 3 instead of 1 naming the check. It now goes to the rows like BLOCKED: a failed row is exit 1 naming it, a running row is exit 4, all rows passing is lag (exit 4 after the bounded re-poll), and green still needs CLEAN. The verify step after a successful merge: every VERIFY FAILED line starts "gh pr merge succeeded;" (exit 1 also means a red check with nothing merged); a MERGED state with no merge commit is worded on its own; and odd JSON (a check-run without a name, a non-object mergeCommit) is noted, never a traceback. A required_status_checks entry without a context is refused instead of a KeyError. A head race that never clears while the head stays at S is exit 3, not 5. The module docstring states the order judge() actually applies. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
…ow it squashes `restack --worktree W --upper BRANCH --lower PR [--dry-run] [--push]` runs AGENTS.md's four merges on a stacked branch once the pull request below it has squash-merged: the lower PR's final head (fetched from refs/pull/PR/head, since the branch is deleted on merge), the squash's first parent, `-s ours` on the squash, then origin/<base>. It refuses (3) unless the lower PR is MERGED with a one-parent merge commit on origin/<base> and W is a clean checkout on BRANCH; stops at the first failing step, names it and its command, and exits 1 with the tree as git left it (run it again after resolving: the finished steps are no-ops); --dry-run prints the four commands and changes nothing, not even by a fetch; --push pushes BRANCH only, plain, after all four succeeded. It never calls `gh pr merge` and grants no merge authority. tools/test_pr_land.py covers it on a disposable bare origin and clone with the fake gh: the upper diff against origin/main equals its own change (the later main commit edits a file the lower PR added, which only merges cleanly because step 3 made the squash the merge base), a conflict at step 1, 2 and 4 is named and left in progress, a resolved conflict resumes, --dry-run leaves HEAD, status and every ref alone, the three refusals, and --push moves refs/heads/BRANCH only and a rejected push is never forced. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
…the credential scan passes ci/source_bundle.py refuses any file that holds the Plex token key next to a 20+ character value. The squash-message shape-rule test deliberately writes such a value, so the literal tripped the repository tree scan (PR #1053). The value is now a module constant formatted into the body, as .claude/hooks/outbound-guard-test.py does; the runtime string is unchanged, so the shape rule is still what refuses it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
…stream on --push, says why a push failed Review round on the restack subcommand, five items: * checked_out also refuses (3) when MERGE_HEAD, CHERRY_PICK_HEAD or REVERT_HEAD resolves. A merge a human resolved and staged but did not commit has an index equal to HEAD, so `status --porcelain` passed it, the fetch ran, step 1 died on "You have not concluded your merge", and stopped() named the wrong step. * --push resolves the branch's upstream. One on origin is pushed as `upper:refs/heads/x` (a checkout made by `git checkout -B tmp origin/x` used to create a stray `tmp` on origin and leave the PR alone), none or a local one as before, and one on any other remote is refused (3) before the first merge. Never forced. * PUSH FAILED prints the `!`, `error:`, `remote:` and `fatal:` lines instead of `To <url>`, the first line of a rejected push, which dropped the reason. * Step 2's message names the lower PR's base instead of main; the usage docstring lists every exit-3 refusal of restack. * --upper equal to the lower PR's base branch is refused (3) before anything is fetched or merged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
…t run time Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB
This was referenced Oct 26, 2026
GLinnik21
added a commit
that referenced
this pull request
Oct 26, 2026
GLinnik21
added a commit
that referenced
this pull request
Oct 26, 2026
GLinnik21
added a commit
that referenced
this pull request
Oct 26, 2026
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.
Stacked on #1053 (base is that PR's branch, so the diff is only
restack). After #1053 squashes, this restacks with the very procedure it implements.What
tools/pr-land.py restack --worktree W --upper BRANCH --lower PR [--dry-run] [--push]After the PR below a stacked PR squash-merges as commit S, the upper branch is brought current by merges, never a rebase:
S^merge --no-ff -s ours S(marks S merged without changing the upper tree, which already has the lower PR's content)origin/<base>Result:
git diff origin/<base>..BRANCHis only the upper PR's own change.Safety, all before any fetch or merge:
origin/<base>and have exactly one parent--uppermust be a plain branch name (not a flag or refspec) and must not be the base branch--dry-runfetches nothing and changes nothingOn a conflict it stops at the failing step and leaves the merge in progress for the human; it never aborts, resets, rebases or forces.
--pushruns only after all four merges, is a plain push, follows the branch's upstream (origin/<name>only; any other remote is refused before the merges), and reports the git rejection reason.Why
The manual procedure lives in AGENTS.md prose and was done by hand. Step 3 alone (
-s ourson the squash) drops whatevermaingained before it; the four-step order is the part that is easy to get wrong.Verification
python3 tools/test_pr_land.py: 88 tests OK (hermetic: temp dirs, a local bare origin, a fakeghon PATH, no network)python3 ci/test_source_bundle.py: 43 tests OK--forcepush each turn the suite red)--dry-runprints "It would run" before three read-only checks that can still refuse; its docstring already says the checks come first.Not verified
refs/pull/N/headis fetched and exercised only against a local bare origin.%(upstream:remotename)was exercised on one git version only (it exists since git 2.13).No tracking issue (owner: none).
🤖 Generated with Claude Code
https://claude.ai/code/session_014bHMduhNfrC8w3qjNhEWdB