Create a gist now

Instantly share code, notes, and snippets.

@mcgwiz /pre-commit
Last active Aug 29, 2015

What would you like to do?
Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
#!/bin/sh
#set -x
git diff-index --cached --quiet HEAD
_ANY=$?
if ((0 == $_ANY)); then
exit 0
fi
# corpus has filename context
_CORPUS=`git diff --cached | grep '^+\(++\|.*NOSHARE\)'`
_TOKEN_FOUND=`echo "$_CORPUS" | grep NOSHARE`
if [ "" == "$_TOKEN_FOUND" ]; then
echo "Commit clean, proceeding..."
exit 0
else
echo "$_CORPUS"
echo '"NOSHARE" found, aborting commit...'
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment