Created
February 16, 2016 04:51
-
-
Save mattbell87/4dce109b3c7098ca8524 to your computer and use it in GitHub Desktop.
Pre-receive hook to validate user and email fields on git commits
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 | |
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') | |
HOSTNAME=$(hostname -f) | |
if [ "$NAME" != "$USER" ] | |
then | |
echo "YOUR COMMIT(S) HAVE NOT BEEN ACCEPTED" | |
echo "" | |
echo "Sorry! Please fix your username before you send changes to $HOSTNAME" | |
echo "" | |
echo "Use the following command on a terminal to update it:" | |
echo ' git config --global user.name "'$USER'"' | |
exit 1 | |
fi | |
VALIDEMAIL='@valid.domain.com' | |
if [[ "$EMAIL" != *"$VALIDEMAIL"* ]] | |
then | |
echo "YOUR COMMIT(S) HAVE NOT BEEN ACCEPTED" | |
echo "" | |
echo "Sorry! Please use your $VALIDEMAIL email account to sent changes to $HOSTNAME" | |
echo "" | |
echo "Use the following command on a terminal to update it:" | |
echo ' git config --global user.email "[email protected]"' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only works if SSH/local commit because web is authenticated differently.