Created
December 18, 2018 13:33
-
-
Save holin/8541f30939f6f964a0e63de6b4116c13 to your computer and use it in GitHub Desktop.
pre-commit hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This is a work-around to get GitHub for Mac to be able to run `node` commands | |
# https://stackoverflow.com/questions/12881975/git-pre-commit-hook-failing-in-github-for-mac-works-on-command-line | |
PATH=$PATH:/usr/local/bin:/usr/local/sbin | |
RESTORE='\033[0m' | |
RED='\033[00;31m' | |
YELLOW='\033[00;33m' | |
BLUE='\033[00;34m' | |
FORBIDDEN=( 'DO NOT COMMIT' 'debug' 'debugger' 'byebug' ) | |
FOUND='' | |
for j in "${FORBIDDEN[@]}" | |
do | |
for i in `git diff --cached --name-only` | |
do | |
# the trick is here...use `git show :file` to output what is staged | |
# test it against each of the FORBIDDEN strings ($j) | |
if echo `git show :$i` | grep -q "$j"; then | |
FOUND+="${BLUE}$i ${RED}contains ${RESTORE}\"$j\"${RESTORE}\n" | |
fi | |
done | |
done | |
# if FOUND is not empty, REJECT the COMMIT | |
# PRINT the results (colorful-like) | |
if [[ ! -z $FOUND ]]; then | |
printf "${YELLOW}COMMIT REJECTED\n" | |
printf "$FOUND" | |
exit 1 | |
fi | |
# nothing found? let the commit happen | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment