What are git hooks?
Git has ability to run special script along with standard git commands. There are many uses for git hooks from enforcing code style before commit to deploying on push, etc. See more on http://githooks.com.
Git pre-commit hook
Git pre-commit hook can help developer accidentally committing temporary changes to the source code made for debugging or testing.
Example of git pre-commit hook
Xcode projects that use Specta or Quick can take advantage of focus tests. Focus tests allows to focus on a subset of a test suite. See how temporarily run a subset of focused examples in Quick. Focus tests speed up Test Driven Development as we can focus on one failing spec at a time. The only problem with focus tests, they require source code modification that we might commit and limit our ability to run full suite of tests. Here is a blog post on Git Pre-Commit Hooks and Specta’s Focused Examples. Unfortunately git hooks are not part of the repository. If we want to share git hooks on the project between multiple developers or even between multiple computers we have to install hooks on each clone.
Git hook manager
One way to share git hooks across multiple clones is to use tool like overcommit . Overcommit is “A fully configurable and extendable Git hook manager”. It adds
.overcommit.yml to configure hooks and allows adding custom hooks to
.git-hooks/ folder in the project root folder.
Overcommit and Xcode
To make overcommit available for Xcode inside IDE we have to install overcommit gem at a system level:
If you are not using RVM - Ruby Version Manager you can skip first line and run this in shell:
Xcode pre-commit hook for Focused Examples
Here is the gist of a pre-commit hook that checks tests for temporary focused examples:
.overcommit.ymlwith the above lines
- save above script to
Now when we try to commit a focused test we get an error message similar to:
|Same message will be shown by Xcode when we try to commit from IDE:|
What hooks would you add for your Xcode project? See how to add pre-commit hook to prevent boiler plate comments.