Skip to content

Fix pre-commit hook swiftformat re-staging#308

Merged
RoyalPineapple merged 1 commit intomainfrom
RoyalPineapple/fix-precommit-hook
Feb 3, 2026
Merged

Fix pre-commit hook swiftformat re-staging#308
RoyalPineapple merged 1 commit intomainfrom
RoyalPineapple/fix-precommit-hook

Conversation

@RoyalPineapple
Copy link
Copy Markdown
Collaborator

@RoyalPineapple RoyalPineapple commented Feb 3, 2026

Summary

The pre-commit hook was formatting Swift files but not re-staging them, leaving the working directory dirty after commits. This fix uses --lint to detect formatting issues first, then prompts the developer before making changes.

Interactive mode: Offers three choices:

  • [f] Fix and commit - format, stage, and proceed with commit
  • [r] Review - format only (no staging), abort to review changes
  • [a] Abort - no changes made

Non-interactive mode: Fails fast without modifying files.

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did you mean to include this?

Comment thread Scripts/git-hooks/pre-commit Outdated

echo ""
echo " [f] Fix and commit"
echo " [r] Review - fix and stage, abort to review"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice to have an option that does not stage so that I can look at what the formatter did. This is something I do almost always.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

good call.

@RoyalPineapple RoyalPineapple force-pushed the RoyalPineapple/fix-precommit-hook branch 2 times, most recently from cc50e20 to e0dde7f Compare February 3, 2026 19:51
- Use --lint to detect formatting issues first
- Prompt user interactively before making changes [f/r/a]
- Fail fast in non-interactive mode (CI)
- Use /dev/tty for interactive prompts in git hooks

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@RoyalPineapple RoyalPineapple force-pushed the RoyalPineapple/fix-precommit-hook branch from e0dde7f to 65634bd Compare February 3, 2026 20:14
@RoyalPineapple RoyalPineapple merged commit 7af99ef into main Feb 3, 2026
5 checks passed
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.

2 participants