Created
February 16, 2020 23:26
-
-
Save Cazz0r/896bf80c184e7077ab219d54ad6d7f31 to your computer and use it in GitHub Desktop.
git pre-commit disallow user from committing
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 | |
# 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') | |
# If we're trying to commit to repo with not allowed email | |
if [[ $EMAIL == *"<REPLACE_ME>"* ]]; then | |
printf "NAME: %s\n" "${NAME}" | |
printf "EMAIL: %s\n" "${EMAIL}" | |
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