[build] Add pre-push formatter hook#17455
Open
AutomatedTester wants to merge 1 commit into
Open
Conversation
Adds .githooks/pre-push so contributors can auto-fix formatting issues before they reach CI. The hook calls scripts/format.sh --pre-push; if formatters modify files it stages them, commits them, and asks the user to re-push — keeping the branch clean without requiring a manual format step. Documents one-time setup (git config core.hooksPath .githooks) in CONTRIBUTING.md under Step 6: Push.
Member
Member
|
I think I'm ok with a pre-push hook in theory, but...
My proposal is that we just encourage people to create their own pre-push or pre-commit hooks. My pre-push hook is just: A separate note, I kind of think --pre-push should default to --lint behavior |
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.

Summary
.githooks/pre-push— a repository-managed hook that runs./scripts/format.sh --pre-pushbefore every push.chore: apply formatters before push) and aborts the push, asking the contributor to re-push with the clean state included.git config core.hooksPath .githooks) and expected push behavior inCONTRIBUTING.mdunder Step 6: Push.Motivation
CI runs
./go formatand fails ifgit diffis non-empty afterwards. Contributors frequently hit this only after opening a PR. This hook catches the issue locally, creates the fix commit automatically, and surfaces a clear re-push message — removing the round-trip.Reviewer notes
git config core.hooksPath .githooksonce per clone. Nothing changes for anyone who does not set this.SKIP_FORMAT_HOOK=1guards the auto-commit path to prevent hook recursion.--no-verifyremains available as an escape hatch (documented as discouraged since CI will still fail).scripts/format.sh; no formatter code is duplicated.Test plan
core.hooksPath, make a change that requires formatting, and verify the hook commits the fix and asks to re-push.git push --no-verifyskips the hook entirely.