Skip to content

Instantly share code, notes, and snippets.

Last active November 28, 2018 08:49
What would you like to do?
Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
git diff-index --cached --quiet HEAD
if ((0 == $_ANY)); then
exit 0
_TOKEN_FOUND=`git diff --cached --name-only | xargs -L1 -I{} sh -c "echo {}; git diff --cached {} | grep -v '^-' | grep -H NOSHARE"`
#_TOKEN_COUNT=`echo -n "$_TOKEN_FOUND" | wc -l`
if [ "" == "$_TOKEN_FOUND" ]; then
echo "Commit clean, proceeding..."
exit 0
echo "$_TOKEN_FOUND"
echo '"NOSHARE" found, aborting commit...'
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment