Created
January 15, 2018 23:00
-
-
Save LastZactionHero/872fb92ef4255a0eaaaacdb4573511a4 to your computer and use it in GitHub Desktop.
Git Pre-Commit Prohibit Debugging Commands
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/sh | |
# | |
# Check to make sure we're not trying to commit debugging code | |
COMMIT_OK=true | |
# Find all staged files with appropriate file types (Ruby, Javascript, Vue) | |
STAGED_MATCHING_FILENAMES=$(git diff --cached --name-only | grep -E '\.js$|.vue|.rb$') | |
# Loop over all of the files | |
for filename in $(echo $STAGED_MATCHING_FILENAMES) | |
do | |
# Javascript or Vue file: | |
# - check for `debugger` | |
if [ $(echo $filename | grep -c -E '\.js$|.vue$') != '0' ]; then | |
if [ $(git diff --cached $filename | grep -c "^+.*debugger") != '0' ]; then | |
echo "GIT CHECK: $filename contains 'debugger'" | |
COMMIT_OK=false | |
fi | |
fi | |
# Ruby file: | |
# - check for 'binding.pry' | |
if [ $(echo $filename | grep -c -E '\.rb$') != '0' ]; then | |
if [ $(git diff --cached $filename | grep -c "^+.*binding\.pry") != '0' ]; then | |
echo "GIT CHECK: $filename contains 'binding.pry'" | |
COMMIT_OK=false | |
fi | |
fi | |
done | |
if [ "$COMMIT_OK" = false ]; then | |
echo "\n\n*** COMMIT REJECTED ***\n\n" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment