Skip to content

fix: preserve partial staging in formatting hooks - #1149

Merged
andiwand merged 2 commits into
mainfrom
review/131-formatting-scripts
Oct 6, 2026
Merged

andiwand merged 2 commits into
mainfrom
review/131-formatting-scripts

Conversation

@andiwand

@andiwand andiwand commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

🤖 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.py pass; 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 existing scripts/tests discovery.

@andiwand
andiwand force-pushed the review/130-document-path-save branch from fd99b7e to 16476bf Compare October 6, 2026 15:07
Base automatically changed from review/130-document-path-save to main October 6, 2026 16:16
andiwand and others added 2 commits October 6, 2026 18:17
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
andiwand force-pushed the review/131-formatting-scripts branch from f9f2f49 to 71a68f5 Compare October 6, 2026 17:02
@andiwand
andiwand merged commit 07cae28 into main Oct 6, 2026
34 of 36 checks passed
@andiwand
andiwand deleted the review/131-formatting-scripts branch October 6, 2026 17:16
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.

1 participant