Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2012 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/4320512 to your computer and use it in GitHub Desktop.
Save anonymous/4320512 to your computer and use it in GitHub Desktop.
this is the hack from @klochner to remove all the dirty binding.pry before committing.
#!/bin/bash
# Checks the files to be committed for the presence of binding.pry
# The array below can be extended for further checks
checks[1]="binding.pry"
element_count=${#checks[@]}
let "element_count = $element_count + 1"
ROOT_DIR="$(pwd)/"
LIST=$(git status | grep -e '\#.*\(modified\|added\)')
ERRORS_BUFFER=""
for file in $LIST
do
if [ "$file" == '#' ]; then
continue
fi
if [ $(echo "$file" | grep 'modified') ]; then
FILE_ACTION="modified"
elif [ $(echo "$file" | grep 'added') ]; then
FILE_ACTION="added"
else
EXTENSION=$(echo "$file")
if [ "$EXTENSION" != "" ]; then
index=1
while [ "$index" -lt "$element_count" ]
do
echo "Checking $FILE_ACTION file: $file [${checks[$index]}]"
ERRORS=$(grep "${checks[$index]}" $ROOT_DIR$file >&1)
if [ "$ERRORS" != "" ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
else
ERRORS_BUFFER="$ERRORS"
fi
echo "${checks[$index]} found in file: $file "
fi
let "index = $index + 1"
done
fi
fi
done
if [ "$ERRORS_BUFFER" != "" ]; then
echo
echo "These errors were found in try-to-commit files: "
echo -e $ERRORS_BUFFER
echo
echo "Can't commit, fix errors first."
exit 1
else
echo "Commited successfully."
fi
@klochner
Copy link

actually from @Saicheg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment