Skip to content

Instantly share code, notes, and snippets.

@waiteb3
Last active December 18, 2015 21:13
Show Gist options
  • Save waiteb3/b694eea1e9b470bee1ee to your computer and use it in GitHub Desktop.
Save waiteb3/b694eea1e9b470bee1ee to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# INSTALL:
# chmod +x pre-push
# mv -i pre-push .git/hooks/pre-push
warning=false
alias grep='grep --color=auto'
LINTS="TODO
console.log
debugger"
for lint in $LINTS; do
MATCHES=$(git diff --stat --cached --name-only origin/master | xargs grep --color=always -n "$lint")
if [[ $MATCHES != "" ]]; then
echo -e "\e[33;1mWARN\e[0m: You have included a file containing a '\e[31;1m$lint\e[0m' in your push"
printf "${MATCHES}\n"
echo
warning=true
fi
done
if $warning; then
exec < /dev/tty
echo -en "\e[34;1m[PRE-PUSH]\e[0m Continue push? (\e[31;1my\e[0m/\e[32;2;1mN\e[0m): "
read REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Not accepting push"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment