Repository navigation
refactor(commit): give the staging gate one name and one StageMode mapping - #3598
Merged
Merged
Conversation
…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]>
worktrunk-bot
approved these changes
Jul 25, 2026
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.
Three simplifications to the staging gate #3588 introduced, all deletions.
stagenames the commit instead of taking a caller's nameWorkingTree::stagetook anactionstring 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:wt merge --no-commitresolves its flags after that gate, and requires a clean tree — which an unmerged path is not. So a conflicted--no-commitrun hits the entry gate, andCannot commitwould 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-squashreportingCannot commitisn'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_untrackedwas deadIt defaulted to
true, and both assignments set it tostage_mode == StageMode::Allimmediately after assigningstage_mode:while the consumer already ANDs with the same condition:
No caller could make it
falsewhile the mode wasAll, so the field never decided anything.One home for the
StageMode→git addmappingThe mapping existed as two matches: one in
stage, one inpreview_commitfor the--dry-runtemp index. Adding a variant meant finding both, and missing the preview would silently produce a--dry-runthat disagreed with the real run.StageMode::add_argsnow 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.rsjustified its entry gate as refusing "ahead of the hooks and the LLM call" — butwt.stageis 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 readCannot commit.cargo run -- hook pre-merge --yesgreen (4562/4562, clippy, fmt, doctests, doc sync). Alsocargo nextest run --features shell-integration-tests(4562/4562) andcargo 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 docclean for the new intra-doc link.