Skip to content

Instantly share code, notes, and snippets.

@mcgwiz mcgwiz/pre-commit
Last active Nov 28, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.