Simple git pre-commit hook for detecting a do-not-commit token (e.g. "NOSHARE").
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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