Skip to content

Instantly share code, notes, and snippets.

@michaeldelorenzo
Created September 24, 2014 21:25
Show Gist options
  • Select an option

  • Save michaeldelorenzo/8399aa992fa291ce8a2e to your computer and use it in GitHub Desktop.

Select an option

Save michaeldelorenzo/8399aa992fa291ce8a2e to your computer and use it in GitHub Desktop.
Put this in .git/hooks/pre-commit then run chmod a+x .git/hooks/pre-commit
#!/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)(\..+)?$'
FORBIDDEN=( debugger ruby-debug )
for i in "${FORBIDDEN[@]}"
do
git diff --cached --name-only| grep ".js" |xargs sed 's/ //g'|grep "ha_mobile.debug=true" && \
echo 'COMMIT REJECTED Found ha_mobile.debug=true references. Please remove them before commiting' && exit 1
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment