Last active
March 20, 2017 09:48
-
-
Save egel/ca14ecaf73f2f1370942e650676c8368 to your computer and use it in GitHub Desktop.
Block to commit if user's email not match
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 | |
# | |
# An example hook script to verify what is about to be committed. | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status after issuing an appropriate message if | |
# it wants to stop the commit. | |
# | |
# To enable this hook, rename this file to "pre-commit". | |
WHITE_LIST='' | |
accept_email() { | |
CURRENT_USER_EMAIL=$(git config --list | grep user.email | awk -F"=" '{print $2}') | |
substring="$1" | |
if [ "${CURRENT_USER_EMAIL}" != "${substring}" ]; then | |
printf "Not match" > /dev/null | |
WHITE_LIST="${WHITE_LIST}\n> ${substring}" | |
else | |
exit 0 | |
fi | |
} | |
# Change for your accepted email addresses | |
accept_email "johndoe@example.com" | |
accept_email "john.doe@example.com" | |
printf "Your current git user.email <%s> NOT MATCH any approved emails\n" "${CURRENT_USER_EMAIL}" | |
printf "%b\n\n" "${WHITE_LIST}" | |
printf "Check ~/.gitconfig for more\n" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage download and save into
.git/hooks/pre-commit
: