Created
October 11, 2015 16:16
-
-
Save waleedsamy/2ee267159ec94812ce27 to your computer and use it in GitHub Desktop.
git pre-commit hook to restrict and validate author email
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
#!/usr/bin/bash | |
# This pre-commit hook will prevent any commit by unvalid author email | |
# or restricted email/s regex | |
restrict_regex=$i | |
email="$(git config user.email)" | |
if [[ "$email" =~ "^[A-Za-z0-9._%+-]+<b>@</b>[A-Za-z0-9.-]+<b>\.</b>[A-Za-z]{2,4}$" ]] | |
then | |
if [ -z "$restrict_regex" ] || [[ "$email" =~ "restrict_regex" ]] | |
then | |
exit 0 | |
else | |
puts "current user email not matched restrioction regex so you are previnted from commiting any code" | |
exit 1 | |
fi | |
else | |
puts | |
puts " Who Are You ?" | |
puts " invalid git author email address" | |
puts | |
puts " try setting your name and email by : " | |
puts " `git config user.name YOUR_NAME` " | |
puts " `git config user.email YOUR_EMAIL` " | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment