Add pre-commit hook that runs fastlane autocorrect#4579
Merged
Conversation
Adds an opt-in pre-commit hook at `.githooks/pre-commit` that runs
`bundle exec fastlane autocorrect` and re-stages any files it modifies
that were already part of the commit. Files outside the staged set are
left as unstaged changes for the developer to review, so the hook
never silently includes work you didn't intend to commit.
Enable once with:
git config core.hooksPath .githooks
Bypass for a single commit:
SKIP_AUTOCORRECT=1 git commit ...
README updated with the setup instructions next to the existing
`fastlane autocorrect` documentation. Hooks live under `.githooks/` so
they're version-controlled and reviewable, rather than a per-clone
`.git/hooks/` script.
Co-Authored-By: Claude <noreply@anthropic.com>
Make the pre-commit autocorrect hook mandatory by wiring it up in the existing `post_install` block of the Podfile. Every `bundle exec pod install` (which the README already requires for setup) now sets `core.hooksPath = .githooks`, so all contributors get autocorrect on commit without an extra opt-in step. The hook itself is unchanged — `SKIP_AUTOCORRECT=1` still bypasses it for a single commit. The README section is updated to reflect that setup is automatic. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, repo-tracked Git pre-commit hook to run bundle exec fastlane autocorrect automatically, with documentation so contributors can enable it via core.hooksPath.
Changes:
- Add
.githooks/pre-committo runfastlane autocorrectbefore commits and attempt to re-stage affected files. - Document hook setup and bypass (
SKIP_AUTOCORRECT=1) inREADME.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| README.md | Documents enabling the checked-in pre-commit hook and how it behaves/bypasses. |
| .githooks/pre-commit | Implements the pre-commit hook that runs autocorrect and re-stages files. |
- Snapshot the staged file list BEFORE running autocorrect so we never re-stage files that weren't already part of the commit (in case autocorrect renames or moves anything). - Stash unstaged work with `--keep-index --include-untracked` before autocorrect runs, so the working tree exactly matches the staged content. After autocorrect, the only unstaged diffs are its own modifications, which are then safe to re-stage. This preserves partial-staged hunks (`git add -p`) and never silently sweeps unrelated unstaged edits into the commit. - A trap restores the stash on any exit path (success, autocorrect failure, or interrupt). If `git stash pop` conflicts, we surface a clear warning pointing at the named stash so the user can resolve it manually. - Update the README sentence to describe the new behaviour precisely (no longer overpromises that it "only stages formatter changes" — that's now actually true, and partial staging is preserved). Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4579 +/- ##
=======================================
Coverage ? 43.24%
=======================================
Files ? 275
Lines ? 16700
Branches ? 0
=======================================
Hits ? 7222
Misses ? 9478
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bgoncal
added a commit
that referenced
this pull request
Apr 30, 2026
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
Adds a checked-in pre-commit hook at
.githooks/pre-committhat runsbundle exec fastlane autocorrectbefore every commit. The existingPodfilepost_installblock wires it up automatically (git config core.hooksPath .githooks), so every contributor runningbundle exec pod install— already part of project setup — gets autocorrect on commit without any extra step.How the hook behaves
SKIP_AUTOCORRECT=1is set in the environment.git commit --amendno-ops).git stash push --keep-index --include-untrackedso the working tree exactly matches the staged content. This means autocorrect runs against the tree being committed, not against in-progress edits.bundle exec fastlane autocorrect.git add -p) are preserved.git stash popconflicts, the hook surfaces a warning pointing at the named stash so it can be resolved manually.Setup
Automatic, via
bundle exec pod install— the existingpost_installblock setscore.hooksPath = .githooksonce. Idempotent and silent on subsequent runs. No extra step for new contributors.Bypass
For mid-rebase, machines without Pods installed, or any other escape hatch.
Files
.githooks/pre-commit(new, executable)Podfile— add thecore.hooksPathsetup at the top of the existingpost_installblockREADME.md— one paragraph next to the existingfastlane autocorrectdocumentationAddressed in review
--keep-indexstash dance now genuinely guarantees only autocorrect's changes are re-stagedTest plan
bundle exec pod installconfigurescore.hooksPath = .githookson first run, silent on subsequent runsgit add -pto stage partial hunks, then commit — hook preserves the unstaged hunksSKIP_AUTOCORRECT=1 git commit ...— bypasses without running autocorrect🤖 Generated with Claude Code