Skip to content

Instantly share code, notes, and snippets.

@kimniche
Created December 14, 2016 21:33
Show Gist options
  • Select an option

  • Save kimniche/67ee898f348d68004869294ceaad71e8 to your computer and use it in GitHub Desktop.

Select an option

Save kimniche/67ee898f348d68004869294ceaad71e8 to your computer and use it in GitHub Desktop.
Error if your commit includes any `console` mentions
#!/bin/bash
LOG="[pre-commit]"
console=`grep -n console $(git diff --name-only --cached) -H --color`
if [ -z "$console" ]; then
tput setaf 2; echo "$LOG no \`console\` left in commit"
tput sgr0
exit 0
else
num=`grep -o console $(git diff --name-only --cached) -H | wc -l`
num="${num// /}"
tput setaf 1; echo "$LOG found $(tput bold)$num$(tput sgr0)$(tput setaf 1) instances of \`console\` in files below, not committing"
tput sgr0; echo -e "$console"
exit 1 # Error out and prevent commit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment