Pre-commit script for iOS projects for automated code review

Step 1. Navigate to project directory using terminal

Example

cd ~/myProjectsFolder/XYZProjectGitCheckout/

Step 2. Further navigate to .git folders

Example

cd .git/

You must have .git folder inside your local check-out. If it's not there, you must be at wrong place.

Step 3. Check if hooks folder exists or not. If not create one and move inside that folder.

mkdir .hooks # optional step
cd .hooks

Step 4. Make sure that you're at valid directory.

pwd
# output should be as follows
# ~/myProjectsFolder/XYZProjectGitCheckout/.git/hooks

Step 5. Create a file named pre-commit

(Yes. Without any extension) and put following contents inside that file.

Step 6. Apply executable permissions.

Step 7. Try to commit the code. In my case it shows following errors because code in not well organized.

Last updated

Was this helpful?