public
Created

git pre commit hook

  • Download Gist
pre-commit
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/bin/bash
## START PRECOMMIT HOOK
# git commit .... <-- run with check
# NOCHECK=1 git commit ... <-- run without check
if [ ! "${NOCHECK}" ]; then
files_modified=`git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`
for f in $files_modified; do
echo "Checking ${f}..."
 
if grep --color -n "console.log" $f; then
echo "File ${f} failed - found 'console.log'"
exit 1
fi
 
if grep --color -n "binding.pry" $f; then
echo "File ${f} failed - found 'binding.pry'"
exit 1
fi
done
fi
exit
## END PRECOMMIT HOOK

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.