Skip to content

Instantly share code, notes, and snippets.

@textarcana
Forked from dy-dx/pre-commit
Created September 2, 2015 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save textarcana/004a7a03e5747a9c0bc6 to your computer and use it in GitHub Desktop.
Save textarcana/004a7a03e5747a9c0bc6 to your computer and use it in GitHub Desktop.
Pre-commit hook that prevents debugging code and merge artifacts from being committed.
#!/bin/bash
# Pre-commit hook that prevents debugging code and merge artifacts from being committed.
FILES_PATTERN='\.(php|ctp|ctpm|css|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