Created
May 10, 2017 11:48
-
-
Save raido/afdef127f0396438093976a99491b0a5 to your computer and use it in GitHub Desktop.
Git pre-commit hook to check if commit is allowed with current user.email
This file contains hidden or 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 | |
# Retrieve author information as Git sees it while commiting | |
AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1 | |
NAME=$(printf '%s\n\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p') | |
EMAIL=$(printf '%s\n\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p') | |
REMOTE_ORIGIN_URL=$(git remote get-url origin) | |
# If we're trying to commit to repo with not allowed email | |
if [[ $REMOTE_ORIGIN_URL != *"<REPLACE_ME>"* ]] && [[ $EMAIL == *"<REPLACE_ME>"* ]]; then | |
printf "NAME: %s\n" "${NAME}" | |
printf "EMAIL: %s\n" "${EMAIL}" | |
printf "REMOTE URL: %s\n" "${REMOTE_ORIGIN_URL}" | |
echo "\nOh, please stop. I cannot allow you to commit with your current email: ${EMAIL}\n" | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment