Last active
January 21, 2016 23:31
-
-
Save dy-dx/7790504 to your computer and use it in GitHub Desktop.
Pre-commit hook that prevents debugging code and merge artifacts from being committed.
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/bash | |
# Pre-commit hook that prevents debugging code and merge artifacts from being committed. | |
FILES_PATTERN='\.(rb|erb|haml|js|coffee)(\..+)?$' | |
FORBIDDEN=( "binding\.pry" "save_and_open_page" "debugger" "it\.only" "describe\.only" ">>>>>>" "<<<<<<" "======" ) | |
# the exit code from `grep -E $FILES_PATTERN` gets swallowed unless the pipefail option is set | |
set -o pipefail | |
FORBIDDEN_FOUND=false | |
# grep for forbidden patterns | |
for i in "${FORBIDDEN[@]}" | |
do | |
git diff --cached --diff-filter=ACMR --name-only | grep -E $FILES_PATTERN | \ | |
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $i \ | |
&& echo -e 'WARNING: Found' $i 'references. Commit with \033[0;32m--no-verify \033[0mto bypass this check.' \ | |
&& FORBIDDEN_FOUND=true | |
done | |
$FORBIDDEN_FOUND && exit 1 || exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice