Skip to content

Instantly share code, notes, and snippets.

@jaymcgavren
Forked from lsaffie/pre-commit
Last active October 5, 2017 06:34
Show Gist options
  • Save jaymcgavren/7517908 to your computer and use it in GitHub Desktop.
Save jaymcgavren/7517908 to your computer and use it in GitHub Desktop.
A Git pre-commit hook to keep me from committing stupid stuff.
#!/bin/bash
# Pre commit hook that prevents FORBIDDEN code from being commited.
# Add unwanted code to the FORBIDDEN array as necessary
FILES_PATTERN='\.(rb|js|coffee|erb|scss|css)(\..+)?$'
FORBIDDEN=( TODO binding.pry FIXME )
for i in "${FORBIDDEN[@]}"
do
git diff --cached --name-only | \
grep -E $FILES_PATTERN | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $i && \
echo 'COMMIT REJECTED Found' $i 'references. Please remove them before commiting.' && exit 1
done
exit 0
@jaymcgavren
Copy link
Author

curl https://gist.github.com/jaymcgavren/7517908/raw/pre-commit > .git/hooks/pre-commit && chmod ug+x .git/hooks/pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment