feat(stack): port replay git helpers (merge-tree + diff-tree) to Rust#1534
Closed
Conversation
Member
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Jun 4, 2026
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 ⛓️ Depends-On RequirementsWaiting for
This rule is failing.Requirement based on the presence of
🔴 👀 Review RequirementsWaiting for
This rule is failing.
🔴 🔎 ReviewsWaiting for
This rule is failing.
🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
When `stack push` force-pushes an amended PR head, the revision-
history compare URL `…/compare/<old>...<new>` is useless when the
rebase moved the base — reviewers see the whole PR diff instead
of just the edit. Python fixes this by replaying the user's
amendment onto `parent(old_sha)` and uploading a synthetic
commit, so compare anchors on `old_sha` and renders only the
edit.
Port the **git-only** half of `mergify_cli/stack/replay.py` to
`mergify-stack::replay`:
- `compute_merged_tree` — `git merge-tree --write-tree
--merge-base=parent(new_sha) parent(old_sha) new_sha` to
produce the merged tree SHA. Same coerce-on-error → None
semantics as Python (conflict, missing parents, old git
without --write-tree all map to None so the caller falls back
to the plain three-dot URL).
- `compute_tree_delta` — parses `git diff-tree -r --raw
--no-renames` into `TreeEntry`s shaped for GitHub's
`POST /repos/.../git/trees`. `D` status emits `sha: None`
→ JSON `null` to instruct GitHub to delete the path; other
statuses we don't recognise are dropped on the floor (Python
matches).
- `mode_to_type` — `160000`→`commit`, `040000`→`tree`,
everything else→`blob`. Public so the eventual orchestrator
can reuse it without a re-import.
Coverage: a real-repo orientation test that mirrors the bug
this whole module exists to fix (PR amended on a stable base —
the diff against `parent_old^{tree}` must contain ONLY the
amendment), plus conflict + missing-parent fallbacks and a
diff-tree parse over modified/added/deleted/type-changed
entries. Wire shape was cross-checked against the Python
implementation byte-for-byte.
The HTTP upload step (`upload_replay_commit` +
`replay_for_revision`) lands separately — it needs
mergify-core's HTTP client wired in, and the git half is
useful on its own when the eventual native `stack push`
arrives.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: Ia95ecd671cb3c38d8d4ff97b90a748eb7b766b1e
97a4c1d to
b652dd4
Compare
Member
Author
Revision history
|
This was referenced Jun 4, 2026
This was referenced Jun 4, 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.
When
stack pushforce-pushes an amended PR head, the revision-history compare URL
…/compare/<old>...<new>is useless when therebase moved the base — reviewers see the whole PR diff instead
of just the edit. Python fixes this by replaying the user's
amendment onto
parent(old_sha)and uploading a syntheticcommit, so compare anchors on
old_shaand renders only theedit.
Port the git-only half of
mergify_cli/stack/replay.pytomergify-stack::replay:compute_merged_tree—git merge-tree --write-tree --merge-base=parent(new_sha) parent(old_sha) new_shatoproduce the merged tree SHA. Same coerce-on-error → None
semantics as Python (conflict, missing parents, old git
without --write-tree all map to None so the caller falls back
to the plain three-dot URL).
compute_tree_delta— parsesgit diff-tree -r --raw --no-renamesintoTreeEntrys shaped for GitHub'sPOST /repos/.../git/trees.Dstatus emitssha: None→ JSON
nullto instruct GitHub to delete the path; otherstatuses we don't recognise are dropped on the floor (Python
matches).
mode_to_type—160000→commit,040000→tree,everything else→
blob. Public so the eventual orchestratorcan reuse it without a re-import.
Coverage: a real-repo orientation test that mirrors the bug
this whole module exists to fix (PR amended on a stable base —
the diff against
parent_old^{tree}must contain ONLY theamendment), plus conflict + missing-parent fallbacks and a
diff-tree parse over modified/added/deleted/type-changed
entries. Wire shape was cross-checked against the Python
implementation byte-for-byte.
The HTTP upload step (
upload_replay_commit+replay_for_revision) lands separately — it needsmergify-core's HTTP client wired in, and the git half is
useful on its own when the eventual native
stack pusharrives.
Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com
Depends-On: #1533