Skip to content

perf(commit): skip the second staging pass when no pre-commit hook ran - #4540

Merged
max-sixty merged 1 commit into
mainfrom
nightly/clean-39556777026
Oct 21, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/clean-39556777026

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

When no pre-commit hook is configured, wt step commit, wt step squash and wt merge now stage once instead of twice. Before this change, each of them ran an extra untracked-file git status and git add -A for nothing. On a large repo, each of those is a full worktree scan.

#4520 made every commit path stage before and after the pre-commit hooks. The pass after the hooks exists so a formatter hook's edits land in the commit. It was gated on hooks being enabled, not on any hook running. execute_hook already returns whether a hook ran, so the second auto_stage now runs only then. When a hook does run, both passes happen as before.

The new test_commit_stages_once_without_pre_commit_hook covers wt merge and wt step commit with no hook configured. It counts the untracked-file scans in the -vv trace: one with this change, two without it. The existing #4520 tests cover the case where a hook runs and still pass.

Locally, the clippy, doc and doctest steps of the pre-merge gate passed. Seven tests failed with and without this change, so the sandbox causes them: it blocks Unix sockets (the non-regular-file and fsmonitor tests) and lacks PowerShell and commit signing.

Since #4520, every commit path (`wt step commit`, `wt step squash`,
`wt merge`) stages before and after the pre-commit hooks. The second
pass exists so a formatter hook's edits land in the commit, but it ran
whenever hooks were enabled, including the common case where no
pre-commit hook is configured. Each extra pass repeats the
untracked-file `git status` and `git add -A`, a full worktree scan on a
large repo.

`execute_hook` already reports whether any hook ran; restage only then.

`test_commit_stages_once_without_pre_commit_hook` counts the
untracked-file scans in the `-vv` trace for `wt merge` and `wt step
commit` with no hook configured; it saw two before this change.
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Oct 21, 2026
@max-sixty
max-sixty merged commit be5c532 into main Oct 21, 2026
37 of 47 checks passed
@max-sixty
max-sixty deleted the nightly/clean-39556777026 branch October 21, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants