refactor(stack): extract shared git helpers into crate::git#1555
Conversation
This was referenced Jun 5, 2026
Member
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Jun 5, 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.
|
33f2759 to
fdab609
Compare
df83c39 to
2dd5d91
Compare
Member
Author
Revision history
|
2dd5d91 to
faf159c
Compare
faf159c to
f4d2fe7
Compare
f4d2fe7 to
c5f353a
Compare
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
34a48aa to
d69a6fb
Compare
c5f353a to
49231a6
Compare
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.
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, andrun_git_silent. Three of the newer leaf modules(
change_type,notes_push,replay) additionally setLC_ALL=C/LANG=C/LANGUAGE=Cbecause they parse English git errormessages; 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)— baseCommandwith-C <dir>(whensupplied) and the forced C locale.
run_git_capture(repo_dir, args)— trimmed stdout orCliError::Genericwith the captured stderr.run_git_silent(repo_dir, args)— same error mapping,output discarded.
resolve_repo_toplevel(repo_dir)—git rev-parse --show-toplevelas aPathBuf.spawn_rebase(repo_dir, base, sequence_editor)— interactiverebase with the optional
GIT_SEQUENCE_EDITORenv (theNonearm is whatstack edit's "fall through to the user'seditor" path used).
shell_quote(value)— POSIX shell single-quote escape.Every consumer module updated to import from
crate::git; theduplicated function bodies (~50-100 lines per module) deleted.
Side effects:
LC_ALL=Clike the leaf modules already did. Downstream callsites that match git error messages by English substring
(
couldn't find remote ref, etc.) now work consistently acrosslocales — a latent bug fix.
spawn_rebasenow takesOption<&str>for the editor (was&strin most consumers,Option<&str>inedit);commands::sync'srun_git/spawn_rebase_with_editorgot renamed to the sharedrun_git_silent/spawn_rebase;commands::push'srun_git_silentsignature changed from&PathtoOption<&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