Skip to content

Add pre-commit hook that runs fastlane autocorrect#4579

Merged
bgoncal merged 3 commits into
mainfrom
claude/add-precommit-autocorrect
Apr 29, 2026
Merged

Add pre-commit hook that runs fastlane autocorrect#4579
bgoncal merged 3 commits into
mainfrom
claude/add-precommit-autocorrect

Conversation

@bgoncal
Copy link
Copy Markdown
Member

@bgoncal bgoncal commented Apr 29, 2026

Summary

Adds a checked-in pre-commit hook at .githooks/pre-commit that runs bundle exec fastlane autocorrect before every commit. The existing Podfile post_install block wires it up automatically (git config core.hooksPath .githooks), so every contributor running bundle exec pod install — already part of project setup — gets autocorrect on commit without any extra step.

How the hook behaves

  1. Skip if SKIP_AUTOCORRECT=1 is set in the environment.
  2. Skip if there are no staged changes (covers git commit --amend no-ops).
  3. Snapshot the staged file list before doing anything, so the re-stage step can only ever touch files that were already part of the commit.
  4. git stash push --keep-index --include-untracked so the working tree exactly matches the staged content. This means autocorrect runs against the tree being committed, not against in-progress edits.
  5. Run bundle exec fastlane autocorrect.
  6. Re-stage anything autocorrect modified — but only for files in the snapshot from step 3. Because step 4 left the working tree clean of unstaged work, the only diffs at this point are autocorrect's own changes. Partial-staged hunks (git add -p) are preserved.
  7. A trap pops the stash on any exit path (success, autocorrect failure, interrupt). If git stash pop conflicts, the hook surfaces a warning pointing at the named stash so it can be resolved manually.

Setup

Automatic, via bundle exec pod install — the existing post_install block sets core.hooksPath = .githooks once. Idempotent and silent on subsequent runs. No extra step for new contributors.

Bypass

SKIP_AUTOCORRECT=1 git commit ...

For mid-rebase, machines without Pods installed, or any other escape hatch.

Files

  • .githooks/pre-commit (new, executable)
  • Podfile — add the core.hooksPath setup at the top of the existing post_install block
  • README.md — one paragraph next to the existing fastlane autocorrect documentation

Addressed in review

  • Snapshot staged files before autocorrect runs (was captured after — fixed)
  • Don't break partial staging or sweep unrelated unstaged edits — the --keep-index stash dance now genuinely guarantees only autocorrect's changes are re-staged
  • README wording matches the new behaviour precisely

Test plan

  • bundle exec pod install configures core.hooksPath = .githooks on first run, silent on subsequent runs
  • Commit a Swift file with intentional formatting issues — hook fixes and re-stages
  • git add -p to stage partial hunks, then commit — hook preserves the unstaged hunks
  • Commit while there are unstaged edits to other files — hook leaves those edits alone
  • SKIP_AUTOCORRECT=1 git commit ... — bypasses without running autocorrect
  • Commit a non-Swift, non-Ruby file — hook runs cleanly with no diff to re-stage

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 29, 2026 00:24
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-commit to run fastlane autocorrect before commits and attempt to re-stage affected files.
  • Document hook setup and bypass (SKIP_AUTOCORRECT=1) in README.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.

Comment thread README.md Outdated
Comment thread .githooks/pre-commit Outdated
Comment thread .githooks/pre-commit Outdated
- 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
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@814152e). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal merged commit 7da3064 into main Apr 29, 2026
15 checks passed
@bgoncal bgoncal deleted the claude/add-precommit-autocorrect branch April 29, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants