-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run SwiftFormat on commit #370
Run SwiftFormat on commit #370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me except for one thing.
FYI @Archdoog, I discussed the problem of how we (try to) push commits from CI that reform your code with the HudHud team last week, since you had complained about how it'd rewrite your branch causing local conflicts, and @ahmedre also ended up having an issue with this causing an inscrutable CI failure, since the action doesn't work on a cross-org fork.
Patrick suggested that we try this approach, which they have been using for 6+ months without issue. It's not as drastic as blanket running swiftformat (etc.) locally, and my understanding is that it only operates on staged files.
While I've been scarred by past experiences with git commit hooks from random JavaScript repos, I think this is a reasonable approach to try. If you're doing Swift development, there's like a 90%+ chance you already have swiftformat installed, and it doesn't use anything else outside git and the Python standard library.
Any objections? We can discuss in tomorrow's meeting if needed.
I'm using https://fork.dev as my git client, so I can show some use cases: Failure when swift file is committed and swiftformat is not installedSuccess after installing swiftformatAndroid should be unaffected |
@ianthetechie could this cause any issue with Windows? for a long time windows didn't support bash but that changed in recent years. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll just merge this for now and if it causes any issues with a Windows user, we'll cross that bridge when we come to it :)
Description
To reduce the feedback loop for a failed build when formatting is not acceptable we agreed to run the formatter as part of the commit. Using https://github.com/hallettj/git-format-staged allows us to only format staged files, leaving other files untouched.
Tasks
./build-ios.sh
Infos for Reviewer
I tested this without SwiftFormat installed: The commit will fail with an error message explaining to install SwiftFormat. You still have the option to ignore the hook and commit directly.
Git, by default, does not distribute hooks when a repository is cloned. This design choice is intentional to prevent arbitrary code execution on users’ machines for security reasons. Therefore we need the workaround, where we configure the git hooks path as part for
build-ios.sh