Skip to content

fix(commit): stage before pre-commit hooks as well as after - #4520

Merged
max-sixty merged 2 commits into
mainfrom
fix/merge-hooks-see-staged
Oct 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/merge-hooks-see-staged

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Since v0.80.0, pre-commit hooks during wt merge and wt step squash no 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 --stage mode. 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 to wt step commit and wt 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 --cached gate and a pre-commit-framework pre-commit run gate both block wt merge and wt step squash again, as on v0.80.0, where main committed the changes. A sed formatter hook's edit is in the commit and in the prompt the commit-message command receives, with a clean tree afterwards. The new test_pre_commit_hook_sees_staged_changes covers wt merge and wt step commit and fails without the fix. test_step_commit_refuses_hook_created_conflict now unstages in its hook, because git merge refuses to start once the index is staged. The other snapshot changes move the auto-staging warning ahead of the hook output.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits October 19, 2026 22:20
#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]>
@max-sixty
max-sixty merged commit 9f08a95 into main Oct 20, 2026
38 checks passed
@max-sixty
max-sixty deleted the fix/merge-hooks-see-staged branch October 20, 2026 15:39
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