Created
October 14, 2019 09:03
-
-
Save glance-/fb2f22016906d2612aec33406c6862f7 to your computer and use it in GitHub Desktop.
Don't allow git commit as root
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/bash | |
# install with ln -s ../../.git-pre-commit.sh .git/hooks/pre-commit | |
AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1 | |
NAME=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p') | |
EMAIL=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p') | |
[ "${NAME}" != root ] && [ "${NAME}" != "Your Name" ] && [[ ! "${EMAIL}" =~ root@.* ]] || { | |
cat <<EOF >&2 | |
Please commit under your own name and email instead of "${NAME} <${EMAIL}>": | |
GIT_AUTHOR_NAME="Your Name" GIT_AUTHOR_EMAIL="your@email.com" git commit | |
EOF | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment