Last active
January 1, 2017 23:26
-
-
Save jasonpilz/b0e0f2c4a211220b5c575168ed08bd89 to your computer and use it in GitHub Desktop.
Git hook to run utilities before commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://gist.githubusercontent.com/jasonpilz/b0e0f2c4a211220b5c575168ed08bd89/raw | |
# This hook runs static analysis tools before each commit. If any of the steps | |
# are interupted by responding with 'no' or 'n', the commit will be aborted. | |
# Install to existing project: | |
# curl -sSL https://git.io/vMt7l > .git/hooks/pre-commit; chmod +x .git/hooks/pre-commit | |
set -e | |
set -o pipefail | |
red=$'\e[1;31m' | |
cyn=$'\e[1;36m' | |
tools=(rubocop reek) | |
exec < /dev/tty | |
run_tool () { | |
if ! $1; then | |
echo "\n$1 found errors in the code. Do you want to continue? ${cyn}no/n or [ENTER]${end}" | |
read input | |
if [ "$input" == "no" ] || [ "$input" == "n" ]; then | |
echo "\n${red}Commit Aborted${end}" | |
exit 1 | |
fi | |
fi | |
} | |
for tool in ${tools[@]}; do | |
run_tool $tool | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment