lunes, 25 de julio de 2016

git pre-commit blacklist

Here's a simple solution if you want git to not allow you to commit debug messages or blacklisted words.

The nice thing about the snippet is that it only counts added lines, not removed, so you can clean code with this pre-commit active, but never make it worse.


FORBIDDEN='declaim\|break'
git diff --cached | grep '^+' |  grep -n $FORBIDDEN && \
 echo "COMMIT REJECTED Found '$FORBIDDEN' references. Please remove them before commiting" &&\
 exit 1

No hay comentarios: