Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Created October 11, 2015 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waleedsamy/2ee267159ec94812ce27 to your computer and use it in GitHub Desktop.
Save waleedsamy/2ee267159ec94812ce27 to your computer and use it in GitHub Desktop.
git pre-commit hook to restrict and validate author email
#!/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