Skip to content

Instantly share code, notes, and snippets.

@rex
Last active December 27, 2016 13:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rex/223b4be50285f6b8b3e06dea50d15887 to your computer and use it in GitHub Desktop.
Save rex/223b4be50285f6b8b3e06dea50d15887 to your computer and use it in GitHub Desktop.
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