Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Git pre-commit hook that will detect COMMITFAIL, @COMMITFAIL, NOCOMMIT, or @NOCOMMIT and fail the commit.
#!/bin/bash
echo "Arguments:"
echo $@
echo "---"
FILES_PATTERN='(\..+)?$'
FORBIDDEN='(@?NOCOMMIT|@?COMMITFAIL)'
if ( git diff --cached --name-only | grep -E $FILES_PATTERN | xargs grep -E --with-filename -n $FORBIDDEN ); then
echo "ERROR: @COMMITFAIL or @NOCOMMIT found. Exiting to save you from yourself."
exit 1
fi
- id: commitfail
name: COMMITFAIL
description: Detect COMMITFAIL, @COMMITFAIL, NOCOMMIT, or @NOCOMMIT and fail the commit.
entry: commitfail-pre-hook.sh
language: script
files: ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment