Repository navigation
fix: preserve partial staging in formatting hooks - #1149
Merged
Merged
Conversation
andiwand
force-pushed
the
review/130-document-path-save
branch
from
October 6, 2026 15:07
fd99b7e to
16476bf
Compare
The hook now formats the staged blob of each C++ file and writes the result back to the index, so a commit with unformatted code still goes through, as before. It formats the working file too only when that file has no unstaged edits, so unstaged changes are never staged. The hook reads the blob with git cat-file, and a failing formatter stops the commit with the index unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MxyTMutqSUJRGfxA8CyzMc
andiwand
force-pushed
the
review/131-formatting-scripts
branch
from
October 6, 2026 17:02
f9f2f49 to
71a68f5
Compare
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.
🤖 Generated with Claude Code
The pre-commit formatter formatted whole working files and staged them, including deliberately unstaged changes. It now formats only the staged blob of each C++ file and writes the result back to the index, so a commit with unformatted code still goes through. It formats the working file as well only when that file has no unstaged edits, so unstaged changes are never staged. Filename handling supports spaces, newlines and leading hyphens, symlinks are skipped, the hook works before the first commit, and a failing formatter stops the commit with the index unchanged.
The explicit formatting script propagates formatter failures, quotes paths, includes WebAssembly sources, and removes the extra shell invocation per file. The root guide describes what the hook does.
Validation: the five tests in
scripts/tests/test_format.pypass; the previous hook fails all four hook tests. A live run on a partially staged file formatted the staged line and left the unstaged edit in the working file. Bash syntax checks pass. These tests join the existingscripts/testsdiscovery.