Created
February 9, 2018 18:40
-
-
Save treyharris/fcdd7d1e2dc9cacdf5dac04feba86927 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/zsh | |
# | |
# A git hook to make sure user.email exists before committing | |
# Used to be you could give a user.email of "(none)" and that would | |
# cause failure to commit, but that's gone now. :-( | |
# | |
# Instead, it assumes the following aliases in .gitconfig: | |
# email-public = "!f() { git config user.email $(git config | |
# --get user.publicemail); git config --get user.email; }; f" | |
# email-work = "!f() { git config user.email $(git config | |
# --get user.workemail); git config --get user.email; }; f" | |
# | |
# And definitions: | |
# [user] | |
# publicemail = [email protected] | |
# workemail = [email protected] | |
# | |
# If the two are the same, just set it. | |
EMAIL=$(git config user.email) | |
if [[ -z "$EMAIL" ]]; then | |
# user.email is empty | |
public_email=$(git config --get user.publicemail) | |
work_email=$(git config --get user.workemail) | |
if [[ "${public_email}" == "${work_email}" ]]; then | |
git email-public | |
exit 0 | |
fi | |
# Work and public emails are different, so abort commit | |
cat >&2 <<EOF | |
ERROR: [pre-commit hook] Aborting commit because user.email is missing. | |
Configure user.email for this repository by running either: | |
'$ git email-public' | |
or | |
'$ git email-work' | |
EOF | |
exit 1 | |
else | |
# user.email is not empty | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment