Permalink
Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
Cannot retrieve contributors at this time.
Cannot retrieve contributors at this time
| # Prevent accidental commits using any of: | |
| # NOCOMMIT, DO_NOT_COMMIT, etc. | |
| # | |
| # How to use: | |
| # 1. Store in ~/.gitconfig.d/hooks/pre-commit | |
| # 2. Make sure it has +x permission `chmod +x ~/.gitconfig.d/hooks/pre-commit` | |
| # 3. Add it into global hooks `git config --global core.hooksPath '~/.gitconfig.d/hooks'` | |
| DISALLOWED_WORDS='\(NO\|NO\(_\| \)\|DO\(_\| \)NOT\(_\| \)\)COMMIT' | |
| if git commit -v --dry-run | grep -e "${DISALLOWED_WORDS}" >/dev/null 2>&1 | |
| then | |
| echo "Trying to commit non-committable code." | |
| git commit -v --dry-run | grep --color -C3 -e "${DISALLOWED_WORDS}" | |
| exit 1 | |
| else | |
| exit 0 | |
| fi |