Skip to content

Instantly share code, notes, and snippets.

@viirre
Last active April 27, 2017 13:06
Show Gist options
  • Save viirre/f1fe68adb9171604b65e33c0648d82d1 to your computer and use it in GitHub Desktop.
Save viirre/f1fe68adb9171604b65e33c0648d82d1 to your computer and use it in GitHub Desktop.
Pre-push git hook to avoid errors in prod
#!/bin/sh
function allTestsShouldPass(){
echo "Running tests..."
vendor/bin/phpunit
if [ $? -ne 0 ]; then
echo " -> ERROR. Tests did not pass, fix them!"
exit 1
fi
}
function checkUntrackedFiles() {
echo "Checking untracked files..."
files=$(git ls-files public/ --others --exclude-standard)
if [ -z "$files" ]; then
echo " -> No untracked files. OK!"
else
echo " -> ERROR: untracked files:"
echo "$files" | sed "s/^/ /"
exit 1
fi
}
exec < /dev/tty
while true; do
read -p "Q. Have you minified assets? Have you checked file/db log for errors? (Y/n) " yn
if [ "$yn" = "" ]; then
yn='Y'
fi
case $yn in
[Yy] ) checkUntrackedFiles; allTestsShouldPass; exit;;
[Nn] ) exit 1;;
* ) echo "Please answer y or n for yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment