Repository navigation
fix(commit): stage before pre-commit hooks as well as after - #4520
Merged
Merged
Conversation
#4321 (3949c21) moved `wt step squash`, and the squash `wt merge` makes by default, to run pre-commit hooks before staging, so a formatter hook's edits would land in the squash commit. A hook that reads the index (`pre-commit run`, lint-staged, `git diff --cached`) then saw nothing staged and passed, so a merge that v0.80.0 blocked committed the offending changes. `wt step commit` and `wt merge --no-squash` had the same order before #4321. All commit paths now stage, run the pre-commit hooks, and stage again with the same `--stage` mode. Hooks see the changes about to be committed, a formatter's edits still land in the commit, and the generated message reads the post-hook index. The second staging warns only about untracked paths the hooks created. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Oct 20, 2026
1 task
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.
Since v0.80.0, pre-commit hooks during
wt mergeandwt step squashno longer see the uncommitted changes in the index. #4321 moved the squash path to run hooks before staging so a formatter hook's edits would land in the squash commit. A hook that reads the index (pre-commit run, lint-staged,git diff --cached) then saw nothing staged and passed, so a merge that v0.80.0 blocked committed the offending changes.All commit paths now stage, run the pre-commit hooks, and stage again with the same
--stagemode. Hooks see the changes, formatter edits still land in the commit, and the generated commit message reads the post-hook index. The second staging warns only about untracked paths the hooks created. This also applies towt step commitandwt merge --no-squash, which ran hooks before staging even in v0.80.0, so an index-reading hook now blocks those commits too, and a failed hook leaves the changes staged there as it already did for squash.Verified with the release-review repros: a
git diff --cachedgate and a pre-commit-frameworkpre-commit rungate both blockwt mergeandwt step squashagain, as on v0.80.0, where main committed the changes. Asedformatter hook's edit is in the commit and in the prompt the commit-message command receives, with a clean tree afterwards. The newtest_pre_commit_hook_sees_staged_changescoverswt mergeandwt step commitand fails without the fix.test_step_commit_refuses_hook_created_conflictnow unstages in its hook, becausegit mergerefuses to start once the index is staged. The other snapshot changes move the auto-staging warning ahead of the hook output.