feat(rust): port stack edit + add rebase-todo machinery#1516
Open
Conversation
Member
Author
|
This pull request is part of a Mergify stack:
|
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.
|
This was referenced Jun 3, 2026
The Rust binary now serves ``mergify stack edit [<commit>]``
natively. The Python implementation (``mergify_cli/stack/edit.py``,
its click registration, and ``mergify_cli/tests/stack/test_edit.py``)
is removed in the same PR.
Third ``stack`` subcommand to land natively. More importantly,
this slice introduces the reusable rebase-todo machinery that
will unlock the rest of the rebase family in subsequent slices:
- ``mergify_stack::rebase_todo::rewrite`` — pure transformer over
the rebase-todo file ``git rebase -i`` would otherwise open in
``$GIT_EDITOR``. Today it speaks one action (``edit``);
``drop``/``reword``/``fixup``/``reorder``/``move``/``squash``
land as additional ``Action`` variants when those ports
follow. The pure split keeps the parser exhaustively unit-
testable without spawning git.
- ``mergify _internal rebase-todo-rewrite --action edit
--sha <SHA> <TODO_PATH>`` — self-invocation target the
orchestrating subcommand sets as ``GIT_SEQUENCE_EDITOR``
before ``git rebase -i``. Hidden, unstable wire format,
listed in ``NATIVE_COMMANDS`` so ``looks_native`` recognises
it even when called from outside the stack subcommand path.
``mergify stack edit <COMMIT>``:
1. Resolves the trunk (reusing the helper added with
``stack new``) and computes ``git merge-base trunk HEAD``.
2. Walks the stack via ``local_commits::read`` and matches the
``<COMMIT>`` argument against either the SHA prefix or the
``Change-Id`` prefix (consistent with ``stack note``).
3. Spawns ``git rebase -i <base>`` with ``GIT_SEQUENCE_EDITOR``
pointing at this binary's
``_internal rebase-todo-rewrite`` subcommand, which marks
the target commit's ``pick`` line as ``edit`` and writes the
todo back. Git proceeds, pauses on that commit, and exits 0
so the user can ``git commit --amend`` + ``git rebase --continue``.
``mergify stack edit`` (no argument) spawns the rebase
interactively — git opens ``$GIT_EDITOR`` on the full todo for
free-form editing. Same flow as Python's ``os.execvp`` fallback.
Exit-code mapping: ``StackNotFound`` for unresolved trunk or
unknown commit prefix, ``InvalidState`` for ambiguous Change-Id
prefix matches, ``GenericError`` for git invocation failures.
Empty stack prints ``No commits in the stack`` and exits 0,
matching Python.
End-to-end coverage lives in ``crates/mergify-cli/tests/stack_edit.rs``
where ``CARGO_BIN_EXE_mergify`` resolves to the freshly-built
binary — spawning ``git rebase -i`` against a real repo
verifies the editor wiring end to end. The pure pieces (commit
prefix matching, todo rewriting) are unit-tested in
``crates/mergify-stack``.
Also ships ``mergify_stack::test_env::isolated_git`` — a test-
only helper that returns a ``Command`` with
``GIT_CONFIG_GLOBAL=/dev/null`` and ``GIT_CONFIG_NOSYSTEM=1``
pre-applied. Without it, the new git-spawning tests were
flaking under workspace ``cargo test`` because of contention
with the developer's global git config. Existing test helpers
in ``trunk.rs``, ``local_commits.rs``,
``commands/{new,note,edit}.rs`` are routed through it.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: Id6b5db4e7c418cb338b99c2b51f752b82d144260
2bed535 to
023c02f
Compare
Member
Author
Revision history
|
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.
The Rust binary now serves
mergify stack edit [<commit>]natively. The Python implementation (
mergify_cli/stack/edit.py,its click registration, and
mergify_cli/tests/stack/test_edit.py)is removed in the same PR.
Third
stacksubcommand to land natively. More importantly,this slice introduces the reusable rebase-todo machinery that
will unlock the rest of the rebase family in subsequent slices:
mergify_stack::rebase_todo::rewrite— pure transformer overthe rebase-todo file
git rebase -iwould otherwise open in$GIT_EDITOR. Today it speaks one action (edit);drop/reword/fixup/reorder/move/squashland as additional
Actionvariants when those portsfollow. The pure split keeps the parser exhaustively unit-
testable without spawning git.
mergify _internal rebase-todo-rewrite --action edit --sha <SHA> <TODO_PATH>— self-invocation target theorchestrating subcommand sets as
GIT_SEQUENCE_EDITORbefore
git rebase -i. Hidden, unstable wire format,listed in
NATIVE_COMMANDSsolooks_nativerecognisesit even when called from outside the stack subcommand path.
mergify stack edit <COMMIT>:stack new) and computesgit merge-base trunk HEAD.local_commits::readand matches the<COMMIT>argument against either the SHA prefix or theChange-Idprefix (consistent withstack note).git rebase -i <base>withGIT_SEQUENCE_EDITORpointing at this binary's
_internal rebase-todo-rewritesubcommand, which marksthe target commit's
pickline aseditand writes thetodo back. Git proceeds, pauses on that commit, and exits 0
so the user can
git commit --amend+git rebase --continue.mergify stack edit(no argument) spawns the rebaseinteractively — git opens
$GIT_EDITORon the full todo forfree-form editing. Same flow as Python's
os.execvpfallback.Exit-code mapping:
StackNotFoundfor unresolved trunk orunknown commit prefix,
InvalidStatefor ambiguous Change-Idprefix matches,
GenericErrorfor git invocation failures.Empty stack prints
No commits in the stackand exits 0,matching Python.
End-to-end coverage lives in
crates/mergify-cli/tests/stack_edit.rswhere
CARGO_BIN_EXE_mergifyresolves to the freshly-builtbinary — spawning
git rebase -iagainst a real repoverifies the editor wiring end to end. The pure pieces (commit
prefix matching, todo rewriting) are unit-tested in
crates/mergify-stack.Also ships
mergify_stack::test_env::isolated_git— a test-only helper that returns a
CommandwithGIT_CONFIG_GLOBAL=/dev/nullandGIT_CONFIG_NOSYSTEM=1pre-applied. Without it, the new git-spawning tests were
flaking under workspace
cargo testbecause of contentionwith the developer's global git config. Existing test helpers
in
trunk.rs,local_commits.rs,commands/{new,note,edit}.rsare routed through it.Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com
Depends-On: #1515