Skip to content

Instantly share code, notes, and snippets.

@LastZactionHero
Created January 15, 2018 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LastZactionHero/872fb92ef4255a0eaaaacdb4573511a4 to your computer and use it in GitHub Desktop.
Save LastZactionHero/872fb92ef4255a0eaaaacdb4573511a4 to your computer and use it in GitHub Desktop.
Git Pre-Commit Prohibit Debugging Commands
#!/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