Skip to content

Instantly share code, notes, and snippets.

@mcgwiz
Last active November 28, 2018 08:49
Show Gist options
  • Save mcgwiz/b9f24d381d84553345d8 to your computer and use it in GitHub Desktop.
Save mcgwiz/b9f24d381d84553345d8 to your computer and use it in GitHub Desktop.
Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
#!/bin/sh
git diff-index --cached --quiet HEAD
_ANY=$?
if ((0 == $_ANY)); then
exit 0
fi
_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
else
echo "$_TOKEN_FOUND"
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