Skip to content

refactor(stack): extract shared git helpers into crate::git#1555

Open
jd wants to merge 1 commit into
devs/jd/feat/rust-stack-new/delete-python-tree-simplify-wheel-ci-pure-rust--04684089from
devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586
Open

refactor(stack): extract shared git helpers into crate::git#1555
jd wants to merge 1 commit into
devs/jd/feat/rust-stack-new/delete-python-tree-simplify-wheel-ci-pure-rust--04684089from
devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586

Conversation

@jd

@jd jd commented Jun 5, 2026

Copy link
Copy Markdown
Member

Every per-command stack module (drop, fixup, reword, reorder,
move, squash, checkout, sync, list, note, edit, setup, new, push)
maintained its own slight variant of shell_quote,
resolve_repo_toplevel, spawn_rebase, run_git_capture, and
run_git_silent. Three of the newer leaf modules
(change_type, notes_push, replay) additionally set
LC_ALL=C/LANG=C/LANGUAGE=C because they parse English git error
messages; the per-command duplicates didn't, which would have
been a flake waiting to happen on non-English systems.

Consolidate into crates/mergify-stack/src/git.rs:

  • git_cmd(repo_dir) — base Command with -C <dir> (when
    supplied) and the forced C locale.
  • run_git_capture(repo_dir, args) — trimmed stdout or
    CliError::Generic with the captured stderr.
  • run_git_silent(repo_dir, args) — same error mapping,
    output discarded.
  • resolve_repo_toplevel(repo_dir)git rev-parse --show-toplevel as a PathBuf.
  • spawn_rebase(repo_dir, base, sequence_editor) — interactive
    rebase with the optional GIT_SEQUENCE_EDITOR env (the
    None arm is what stack edit's "fall through to the user's
    editor" path used).
  • shell_quote(value) — POSIX shell single-quote escape.

Every consumer module updated to import from crate::git; the
duplicated function bodies (~50-100 lines per module) deleted.
Side effects:

  • The previously locale-unaware per-command helpers now force
    LC_ALL=C like the leaf modules already did. Downstream call
    sites that match git error messages by English substring
    (couldn't find remote ref, etc.) now work consistently across
    locales — a latent bug fix.
  • Call-site signature updates: spawn_rebase now takes
    Option<&str> for the editor (was &str in most consumers,
    Option<&str> in edit); commands::sync's run_git /
    spawn_rebase_with_editor got renamed to the shared
    run_git_silent / spawn_rebase; commands::push's
    run_git_silent signature changed from &Path to
    Option<&Path>.

Addresses Copilot's review feedback on PR #1518 (stack fixup)
about helper duplication across drop/edit/fixup/... — the
extraction unifies all 13 consumer modules in one commit.

All 241 mergify-stack tests + the rest of the workspace pass.

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

Depends-On: #1554

@jd

jd commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(rust): port stack checkout to native Rust #1522
2 feat(rust): port stack sync to native Rust #1523
3 feat(rust): port stack list + stack open to native Rust #1524
4 feat(rust): port stack hooks + stack setup to native Rust #1527
5 feat(rust): port stack push end-to-end + delete Python push.py #1553
6 chore: delete Python tree + simplify wheel/CI for pure-Rust binary #1554
7 refactor(stack): extract shared git helpers into crate::git #1555 👈
8 ci(workflows): align smoke-test-binary on python 3.14 #1557

@mergify

mergify Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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,})

@mergify mergify Bot requested a review from a team June 5, 2026 08:21
@jd jd marked this pull request as ready for review June 5, 2026 09:28
@jd jd force-pushed the devs/jd/feat/rust-stack-new/delete-python-tree-simplify-wheel-ci-pure-rust--04684089 branch from 33f2759 to fdab609 Compare June 5, 2026 09:38
@jd jd force-pushed the devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586 branch from df83c39 to 2dd5d91 Compare June 5, 2026 09:38
@jd jd temporarily deployed to func-tests-live June 5, 2026 09:38 — with GitHub Actions Inactive
@jd

jd commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

Revision history

# Type Changes Reason Date
1 initial df83c39 2026-06-05 09:38 UTC
2 rebase df83c39 → 2dd5d91 (rebase only) 2026-06-05 09:38 UTC
3 rebase 2dd5d91 → faf159c (rebase only) 2026-06-05 11:15 UTC
4 rebase faf159c → f4d2fe7 (rebase only) 2026-06-05 12:37 UTC
5 rebase f4d2fe7 → c5f353a (rebase only) 2026-06-08 11:31 UTC
6 rebase c5f353a → 49231a6 (rebase only) 2026-06-08 15:03 UTC

@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 5, 2026 09:39 Failure
@jd jd force-pushed the devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586 branch from 2dd5d91 to faf159c Compare June 5, 2026 11:15
@jd jd temporarily deployed to func-tests-live June 5, 2026 11:15 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live June 5, 2026 11:15 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 5, 2026 11:15 Failure
@jd jd force-pushed the devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586 branch from faf159c to f4d2fe7 Compare June 5, 2026 12:37
@jd jd temporarily deployed to func-tests-live June 5, 2026 12:37 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 5, 2026 12:37 Failure
@jd jd force-pushed the devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586 branch from f4d2fe7 to c5f353a Compare June 8, 2026 11:31
@jd jd temporarily deployed to func-tests-live June 8, 2026 11:31 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 8, 2026 11:31 Failure
Every per-command stack module (drop, fixup, reword, reorder,
move, squash, checkout, sync, list, note, edit, setup, new, push)
maintained its own slight variant of `shell_quote`,
`resolve_repo_toplevel`, `spawn_rebase`, `run_git_capture`, and
`run_git_silent`. Three of the newer leaf modules
(`change_type`, `notes_push`, `replay`) additionally set
`LC_ALL=C/LANG=C/LANGUAGE=C` because they parse English git error
messages; the per-command duplicates didn't, which would have
been a flake waiting to happen on non-English systems.

Consolidate into `crates/mergify-stack/src/git.rs`:

- `git_cmd(repo_dir)` — base `Command` with `-C <dir>` (when
  supplied) and the forced C locale.
- `run_git_capture(repo_dir, args)` — trimmed stdout or
  `CliError::Generic` with the captured stderr.
- `run_git_silent(repo_dir, args)` — same error mapping,
  output discarded.
- `resolve_repo_toplevel(repo_dir)` — `git rev-parse
  --show-toplevel` as a `PathBuf`.
- `spawn_rebase(repo_dir, base, sequence_editor)` — interactive
  rebase with the optional `GIT_SEQUENCE_EDITOR` env (the
  `None` arm is what `stack edit`'s "fall through to the user's
  editor" path used).
- `shell_quote(value)` — POSIX shell single-quote escape.

Every consumer module updated to import from `crate::git`; the
duplicated function bodies (~50-100 lines per module) deleted.
Side effects:

- The previously locale-unaware per-command helpers now force
  `LC_ALL=C` like the leaf modules already did. Downstream call
  sites that match git error messages by English substring
  (`couldn't find remote ref`, etc.) now work consistently across
  locales — a latent bug fix.
- Call-site signature updates: `spawn_rebase` now takes
  `Option<&str>` for the editor (was `&str` in most consumers,
  `Option<&str>` in `edit`); `commands::sync`'s `run_git` /
  `spawn_rebase_with_editor` got renamed to the shared
  `run_git_silent` / `spawn_rebase`; `commands::push`'s
  `run_git_silent` signature changed from `&Path` to
  `Option<&Path>`.

Addresses Copilot's review feedback on PR #1518 (stack fixup)
about helper duplication across drop/edit/fixup/... — the
extraction unifies all 13 consumer modules in one commit.

All 241 mergify-stack tests + the rest of the workspace pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: I4382c5869113a1efb63072c76c08c581133c96da
@jd jd force-pushed the devs/jd/feat/rust-stack-new/delete-python-tree-simplify-wheel-ci-pure-rust--04684089 branch from 34a48aa to d69a6fb Compare June 8, 2026 15:02
@jd jd force-pushed the devs/jd/feat/rust-stack-new/extract-shared-git-helpers-crate-git--4382c586 branch from c5f353a to 49231a6 Compare June 8, 2026 15:03
@jd jd temporarily deployed to func-tests-live June 8, 2026 15:03 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live June 8, 2026 15:03 — with GitHub Actions Inactive
@mergify mergify Bot had a problem deploying to Mergify Merge Protections June 8, 2026 15:03 Failure
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