Skip to content

feat(rust): port stack new to native Rust#1513

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/jd/feat/rust-stack-new/port-stack-native-rust--a8c23565
Jun 3, 2026
Merged

feat(rust): port stack new to native Rust#1513
mergify[bot] merged 1 commit into
mainfrom
devs/jd/feat/rust-stack-new/port-stack-native-rust--a8c23565

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented Jun 3, 2026

The Rust binary now serves mergify stack new <name> natively.
The Python implementation (mergify_cli/stack/new.py, its
click registration in mergify_cli/stack/cli.py, and the unit
suite in mergify_cli/tests/stack/test_new.py) is removed in
the same PR — the port-and-delete rule keeps a single live copy
of every command.

This is the first stack subcommand to land natively; the
rest still flow through the Python shim. The dispatcher peeks at
argv[0] after stack — when it's new, the rest is
secondary-parsed by clap and dispatched into
mergify_stack::commands::new; everything else continues to
forward to mergify-py-shim verbatim.

mergify stack new <NAME> [-b REMOTE/BRANCH] [--checkout/--no-checkout]:

  1. Resolves the base ref. --base origin/main is used verbatim;
    otherwise mergify_stack::trunk::get_trunk mirrors the Python
    utils.get_trunk chain: branch.<current>.{remote,merge}
    tracking → refs/remotes/origin/HEAD fallback → set tracking
    on the current branch with a yellow notice → StackNotFound
    when both fail.
  2. git fetch <remote> <branch> brings the base up to date.
  3. git checkout --track -b <name> <base> (default) or
    git branch --track <name> <base> (--no-checkout)
    creates the branch.

Exit-code mapping matches Python: StackNotFound when the
trunk can't be resolved, GenericError for fetch/branch
failures, Success on the happy path.

The new mergify-stack::trunk module is reusable by future
stack drop/stack edit/stack sync ports — the helpers
git_get_branch_name, git_get_target_branch,
git_get_target_remote, and get_trunk are public.

mergify stack new --help is now served by clap; the bare
mergify stack --help still shims to Python and lists the
remaining Python-only subcommands.

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

Copilot AI review requested due to automatic review settings June 3, 2026 10:35
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 3, 2026 10:35 Failure
@jd jd temporarily deployed to func-tests-live June 3, 2026 10:35 — with GitHub Actions Inactive
@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.

🟢 🤖 Continuous Integration

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

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 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)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports mergify stack new <NAME> from the Python shim to a native Rust implementation, and removes the Python command + its unit tests to keep a single live implementation during the migration. It also introduces a reusable mergify-stack::trunk module to resolve the trunk ref (<remote>/<branch>) for future native stack subcommands.

Changes:

  • Add native Rust implementation of stack new plus dispatch in the Rust mergify binary.
  • Add mergify-stack::trunk helpers to mirror Python’s trunk resolution and upstream auto-set behavior.
  • Remove the Python stack new implementation, click registration, and Python unit tests for that subcommand.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mergify_cli/tests/stack/test_new.py Removes Python unit tests for the deleted Python stack new implementation.
mergify_cli/stack/new.py Removes the Python implementation of stack new.
mergify_cli/stack/cli.py Removes click wiring for the Python stack new subcommand.
crates/mergify-stack/src/trunk.rs Adds Rust trunk-resolution module (tracking config → origin/HEAD fallback → auto-set upstream).
crates/mergify-stack/src/lib.rs Exposes new commands and trunk modules from mergify-stack.
crates/mergify-stack/src/commands/new.rs Adds Rust stack new implementation (fetch + branch creation) with unit tests.
crates/mergify-stack/src/commands/mod.rs Introduces the commands module namespace for stack subcommands.
crates/mergify-cli/src/main.rs Adds native dispatch for mergify stack new while keeping other stack subcommands shimmed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/mergify-cli/src/main.rs Outdated
Comment thread crates/mergify-stack/src/commands/new.rs Outdated
@jd jd marked this pull request as ready for review June 3, 2026 13:21
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 3, 2026

@jd this pull request is now in conflict 😩

@mergify mergify Bot added the conflict label Jun 3, 2026
The Rust binary now serves ``mergify stack new <name>`` natively.
The Python implementation (``mergify_cli/stack/new.py``, its
click registration in ``mergify_cli/stack/cli.py``, and the unit
suite in ``mergify_cli/tests/stack/test_new.py``) is removed in
the same PR — the port-and-delete rule keeps a single live copy
of every command.

This is the first ``stack`` subcommand to land natively; the
rest still flow through the Python shim. The dispatcher peeks at
``argv[0]`` after ``stack`` — when it's ``new``, the rest is
secondary-parsed by clap and dispatched into
``mergify_stack::commands::new``; everything else continues to
forward to ``mergify-py-shim`` verbatim.

``mergify stack new <NAME> [-b REMOTE/BRANCH]
[--checkout/--no-checkout]``:

1. Resolves the base ref. ``--base origin/main`` is used verbatim;
   otherwise ``mergify_stack::trunk::get_trunk`` mirrors the Python
   ``utils.get_trunk`` chain: ``branch.<current>.{remote,merge}``
   tracking → ``refs/remotes/origin/HEAD`` fallback → set tracking
   on the current branch with a yellow notice → ``StackNotFound``
   when both fail.
2. ``git fetch <remote> <branch>`` brings the base up to date.
3. ``git checkout --track -b <name> <base>`` (default) or
   ``git branch --track <name> <base>`` (``--no-checkout``)
   creates the branch.

Exit-code mapping matches Python: ``StackNotFound`` when the
trunk can't be resolved, ``GenericError`` for fetch/branch
failures, ``Success`` on the happy path.

The new ``mergify-stack::trunk`` module is reusable by future
``stack drop``/``stack edit``/``stack sync`` ports — the helpers
``git_get_branch_name``, ``git_get_target_branch``,
``git_get_target_remote``, and ``get_trunk`` are public.

``mergify stack new --help`` is now served by clap; the bare
``mergify stack --help`` still shims to Python and lists the
remaining Python-only subcommands.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: Ia8c23565155a0a64bd4f8b4b66fd493ab1fc0cc5
@jd jd force-pushed the devs/jd/feat/rust-stack-new/port-stack-native-rust--a8c23565 branch from 50050a2 to e5b00a8 Compare June 3, 2026 13:25
@jd
Copy link
Copy Markdown
Member Author

jd commented Jun 3, 2026

Revision history

# Type Changes Reason Date
1 initial 50050a2 2026-06-03 13:25 UTC
2 content 50050a2 → e5b00a8 rebase onto main, align parse_remote_branch error wording with Python trunk_type (Bc6GtplU), preserve underlying get_trunk error inside StackNotFound (Bc6Gtpl-), apply rustfmt 2026-06-03 13:25 UTC

@jd jd temporarily deployed to func-tests-live June 3, 2026 13:25 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live June 3, 2026 13:25 — with GitHub Actions Inactive
@mergify mergify Bot deployed to Mergify Merge Protections June 3, 2026 13:25 Active
@mergify mergify Bot requested a review from a team June 3, 2026 13:39
@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 new to native Rust #1513 👈
2 feat(rust): port stack note to native Rust #1515

@mergify mergify Bot requested a review from a team June 3, 2026 14:17
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 3, 2026

Merge Queue Status

  • Entered queue2026-06-03 14:43 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-06-03 14:43 UTC · at e5b00a8e721b200c66cc12f009a8cacc02dccc19 · squash

This pull request spent 12 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label Jun 3, 2026
@mergify mergify Bot merged commit 029c388 into main Jun 3, 2026
36 checks passed
@mergify mergify Bot deleted the devs/jd/feat/rust-stack-new/port-stack-native-rust--a8c23565 branch June 3, 2026 14:43
@mergify mergify Bot removed the queued label Jun 3, 2026
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.

4 participants