Skip to content

refactor(commit): give the staging gate one name and one StageMode mapping - #3598

Merged
max-sixty merged 1 commit into
mainfrom
fix-relocate-unmerged-paths-gate
Jul 25, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix-relocate-unmerged-paths-gate

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Three simplifications to the staging gate #3588 introduced, all deletions.

stage names the commit instead of taking a caller's name

WorkingTree::stage took an action string purely so its refusal could name the command the user typed. But staging on the user's behalf happens for exactly one reason — a commit is about to run — so the string was a constant wearing a parameter's clothes. It now names the commit, and three call-site strings go with it.

The entry gates keep their action, and the reason is worth stating because it's what stopped me deleting the parameter outright. An entry point often doesn't yet know it will commit at all:

current_wt.ensure_no_unmerged_paths("merge")?;   // src/commands/merge.rs:179
...
let ResolvedMergeFlags { commit, .. } = flags.resolve(&resolved.merge);   // :187

wt merge --no-commit resolves its flags after that gate, and requires a clean tree — which an unmerged path is not. So a conflicted --no-commit run hits the entry gate, and Cannot commit would be actively wrong for a command explicitly told not to commit. The two gates know different things, and now say different things for that reason.

This also settles the seam #3588 documented as a tradeoff: wt merge --no-squash reporting Cannot commit isn't a wrong label to be fixed later, it's the funnel correctly naming the only step it guards, at a point where the flags have resolved and the commit is certain.

CommitOptions::warn_about_untracked was dead

It defaulted to true, and both assignments set it to stage_mode == StageMode::All immediately after assigning stage_mode:

options.stage_mode = stage_mode;
options.warn_about_untracked = stage_mode == super::commit::StageMode::All;

while the consumer already ANDs with the same condition:

if self.warn_about_untracked && self.stage_mode == StageMode::All {

No caller could make it false while the mode was All, so the field never decided anything.

One home for the StageMode → git add mapping

The mapping existed as two matches: one in stage, one in preview_commit for the --dry-run temp index. Adding a variant meant finding both, and missing the preview would silently produce a --dry-run that disagreed with the real run. StageMode::add_args now owns it. stage's two per-arm .context() strings collapse into one, which costs nothing the args don't already say.

Also

src/commands/step/squash.rs justified its entry gate as refusing "ahead of the hooks and the LLM call" — but wt.stage is ahead of both too, so that reason no longer distinguished it. The gate is still worth keeping; what it uniquely precedes is the pre-commit approval prompt, so the comment says that now.

Verification

No user-visible message changes, and the tests confirm it rather than assert it: the pre-merge gate reports no snapshots to review. Every refusal a test pins comes from an entry gate, which kept its name, and the one funnel-driven snapshot (step_commit_refuses_hook_created_conflict) already read Cannot commit.

cargo run -- hook pre-merge --yes green (4562/4562, clippy, fmt, doctests, doc sync). Also cargo nextest run --features shell-integration-tests (4562/4562) and cargo clippy --all-targets --features shell-integration-tests, which the gate doesn't compile — the blind spot that matters for removing a struct field. RUSTDOCFLAGS=-Dwarnings cargo doc clean for the new intra-doc link.

This was written by Claude Code on behalf of Maximilian

…pping

`WorkingTree::stage` took an `action` string so its refusal could name the
caller's command. It only ever guards a commit, so the string is a constant:
drop the parameter and name the commit. The entry gates keep their `action`,
where the command genuinely doesn't know yet whether it will commit —
`wt merge` gates before resolving `--no-commit`.

Delete `CommitOptions::warn_about_untracked`. It defaulted to true and both
assignments set it to `stage_mode == All` immediately after assigning
`stage_mode`, which the callee already ANDs with.

Add `StageMode::add_args`, so staging the real index and mirroring the mode
into a throwaway index for `wt step commit --dry-run` read the git
invocation from one place instead of two matches.

No user-visible message changes: the entry gates own every refusal a test
pins, and the funnel's snapshot already read `Cannot commit`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 5f1ce23 into main Jul 25, 2026
38 checks passed
@max-sixty
max-sixty deleted the fix-relocate-unmerged-paths-gate branch July 25, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants