Skip to content

feat(rust): port stack sync to native Rust#1523

Draft
jd wants to merge 1 commit into
devs/jd/feat/rust-stack-new/port-stack-checkout-native-rust--71e74caefrom
devs/jd/feat/rust-stack-new/port-stack-sync-native-rust--7f75be87
Draft

feat(rust): port stack sync to native Rust#1523
jd wants to merge 1 commit into
devs/jd/feat/rust-stack-new/port-stack-checkout-native-rust--71e74caefrom
devs/jd/feat/rust-stack-new/port-stack-sync-native-rust--7f75be87

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented Jun 3, 2026

The Rust binary now serves mergify stack sync [--dry-run]
natively. The Python stack_sync entry point and
test_sync.py are gone; the click registration is gone too.

The rest of mergify_cli/stack/sync.py (SyncStatus,
get_sync_status, smart_rebase, _write_drop_script)
is kept for now because the still-Python stack push calls
smart_rebase directly. The whole file is queued for deletion
with the stack push port.

New infrastructure that the remaining slices (list,
push, open) will reuse:

  • mergify_stack::sync_status — sync-specific classifier that
    walks the local stack commits, matches each to a remote PR by
    Change-Id (with the cross-prefix tolerance Python's
    pop_remote_change had), and buckets them into
    MergedCommit (closed-and-merged AND head SHA matches the
    local commit) and RemainingCommit (everything else). The
    full create/update/skip-up-to-date classifier needed by
    stack push/stack list lands with those slices.
  • mergify_stack::stack_context::check_local_branch — rejects
    local branches whose shape matches the auto-generated
    <prefix>/.../<slug>--<hex8> or legacy /I<40hex> forms.
  • MERGIFY_GITHUB_SERVER env var on
    stack_context::resolve_github_server — bypasses git config
    and the unconditional https:// coercion, so integration
    tests can point at a wiremock server speaking plain http.

mergify stack sync:

  1. Validates the local branch isn't an auto-generated leaf branch
    and that it isn't the trunk itself.
  2. Resolves user/repo, the trunk, and the
    git merge-base --fork-point (falling back to plain
    merge-base for sandboxes with no reflog).
  3. Searches GitHub for the stack PRs and classifies each local
    commit via sync_status::classify.
  4. --dry-run prints a plan and exits 0. Otherwise:
    • When every commit is merged or none are, git pull --rebase.
    • Mixed case: git rebase -i <trunk> with
      GIT_SEQUENCE_EDITOR pointing at this binary's
      _internal rebase-todo-rewrite --action drop --shas <merged>
      — single rebase pass, no separate drop step.

End-to-end coverage in
crates/mergify-cli/tests/stack_sync.rs (3 cases against a
real binary + wiremock + real git): up-to-date when no PRs are
merged, dry-run lists merged commits, validation rejects
auto-generated branch names. The classifier adds 7 unit tests
(merged / amended-after-merge / open / no-pr / cross-prefix
match / all_merged / up_to_date predicates).

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

Depends-On: #1522

@jd
Copy link
Copy Markdown
Member Author

jd commented Jun 3, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(rust): port stack note to native Rust #1515
2 feat(rust): port stack edit + add rebase-todo machinery #1516
3 feat(rust): port stack drop to native Rust #1517
4 feat(rust): port stack fixup to native Rust #1518
5 feat(rust): port stack reword to native Rust #1519
6 feat(rust): port stack reorder + stack move to native Rust #1520
7 feat(rust): port stack squash to native Rust #1521
8 feat(rust): port stack checkout to native Rust #1522
9 feat(rust): port stack sync to native Rust #1523 👈
10 feat(rust): port stack list + stack open to native Rust #1524

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 3, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 ⛓️ Depends-On Requirements

Waiting for

This rule is failing.

Requirement based on the presence of Depends-On in the body of the pull request

🔴 👀 Review Requirements

Waiting for

  • #approved-reviews-by>=2
This rule is failing.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🔴 🔎 Reviews

Waiting for

  • #review-requested = 0
This rule is failing.
  • #review-requested = 0
  • #changes-requested-reviews-by = 0
  • #review-threads-unresolved = 0

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?:

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

The Rust binary now serves ``mergify stack sync [--dry-run]``
natively. The Python ``stack_sync`` entry point and
``test_sync.py`` are gone; the click registration is gone too.

The rest of ``mergify_cli/stack/sync.py`` (``SyncStatus``,
``get_sync_status``, ``smart_rebase``, ``_write_drop_script``)
is kept for now because the still-Python ``stack push`` calls
``smart_rebase`` directly. The whole file is queued for deletion
with the ``stack push`` port.

New infrastructure that the remaining slices (``list``,
``push``, ``open``) will reuse:

- ``mergify_stack::sync_status`` — sync-specific classifier that
  walks the local stack commits, matches each to a remote PR by
  ``Change-Id`` (with the cross-prefix tolerance Python's
  ``pop_remote_change`` had), and buckets them into
  ``MergedCommit`` (closed-and-merged AND head SHA matches the
  local commit) and ``RemainingCommit`` (everything else). The
  full create/update/skip-up-to-date classifier needed by
  ``stack push``/``stack list`` lands with those slices.
- ``mergify_stack::stack_context::check_local_branch`` — rejects
  local branches whose shape matches the auto-generated
  ``<prefix>/.../<slug>--<hex8>`` or legacy ``/I<40hex>`` forms.
- ``MERGIFY_GITHUB_SERVER`` env var on
  ``stack_context::resolve_github_server`` — bypasses git config
  and the unconditional ``https://`` coercion, so integration
  tests can point at a wiremock server speaking plain ``http``.

``mergify stack sync``:

1. Validates the local branch isn't an auto-generated leaf branch
   and that it isn't the trunk itself.
2. Resolves ``user/repo``, the trunk, and the
   ``git merge-base --fork-point`` (falling back to plain
   ``merge-base`` for sandboxes with no reflog).
3. Searches GitHub for the stack PRs and classifies each local
   commit via ``sync_status::classify``.
4. ``--dry-run`` prints a plan and exits 0. Otherwise:
   - When every commit is merged or none are, ``git pull --rebase``.
   - Mixed case: ``git rebase -i <trunk>`` with
     ``GIT_SEQUENCE_EDITOR`` pointing at this binary's
     ``_internal rebase-todo-rewrite --action drop --shas <merged>``
     — single rebase pass, no separate drop step.

End-to-end coverage in
``crates/mergify-cli/tests/stack_sync.rs`` (3 cases against a
real binary + wiremock + real git): up-to-date when no PRs are
merged, dry-run lists merged commits, validation rejects
auto-generated branch names. The classifier adds 7 unit tests
(merged / amended-after-merge / open / no-pr / cross-prefix
match / ``all_merged`` / ``up_to_date`` predicates).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: I7f75be875289707f492ecbf59f6bcb6530554f24
@jd jd force-pushed the devs/jd/feat/rust-stack-new/port-stack-checkout-native-rust--71e74cae branch from 0da0845 to b09a7f8 Compare June 3, 2026 21:01
@jd jd force-pushed the devs/jd/feat/rust-stack-new/port-stack-sync-native-rust--7f75be87 branch from 694deb9 to 38d547f Compare June 3, 2026 21:01
@jd
Copy link
Copy Markdown
Member Author

jd commented Jun 3, 2026

Revision history

# Type Changes Reason Date
1 initial 694deb9 2026-06-03 21:01 UTC
2 content 694deb9 → 38d547f (raw) ruff format fix on the stub sync.py kept for stack/push.py 2026-06-03 21:01 UTC

@jd jd temporarily deployed to func-tests-live June 3, 2026 21:01 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live June 3, 2026 21:01 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 3, 2026 21:01 Failure
@mergify mergify Bot requested a review from a team June 3, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant