Skip to content

Instantly share code, notes, and snippets.

@amitasaurus
Last active April 11, 2020 02:40
Show Gist options
  • Save amitasaurus/cc2dccbba8ca746163f4799fac3ebd4d to your computer and use it in GitHub Desktop.
Save amitasaurus/cc2dccbba8ca746163f4799fac3ebd4d to your computer and use it in GitHub Desktop.
Custom pre commit git hook to check for FIXME
The hooks are all stored in the hooks subdirectory of the Git directory that’s .git/hooks
Open your terminal or powershell for windows;
Navigate to $ cd /path-to-your-git-repo/.git/hooks
$ touch pre-commit
$ cp pre-commit.sample pre-commit
$ chmod +x pre-commit
Open the pre-commit script and start the real scripting with your text editor
$ open -e pre-commit
add this
#!/bin/sh
matches=$(git diff --cached | grep -E '\+.*?FIXME')
if [ "$matches" != "" ]
then
echo "'FIXME' tag is detected."
echo "Please fix it before committing."
echo " ${matches}"
exit 1
fi
References:
https://medium.com/the-andela-way/git-hooks-beautifully-automate-tasks-stages-bfb29f42fea1
https://gist.github.com/kuy/5d1151fd5897a9b84c06
NOTE: to skip the hook use `--no-verify` flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment