Created
January 25, 2021 21:31
-
-
Save particleflux/27759f807fad6b7e1e7af28dfb695b1e to your computer and use it in GitHub Desktop.
Check git user config on first local commit
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/env bash | |
verified=$(git config --type=bool hooks.userverified) | |
# grab input | |
exec < /dev/tty | |
exec 1>&2 | |
if [[ "$verified" != "true" ]]; then | |
echo "Checking committer info..." | |
echo "Current author information:" | |
echo "$(git config user.name) <$(git config user.email)>" | |
while read -p "Is the author set correct? (y/n) " yn; do | |
case $yn in | |
[Yy] ) | |
echo "First local commit correct, disabled check" | |
git config hooks.userverified true | |
break | |
;; | |
[Nn] ) | |
echo "Please update author info!"; | |
exit 1 | |
;; | |
* ) | |
echo "Please answer y (yes) or n (no):" && continue; | |
esac | |
done | |
fi |
Small note: You should probably run git config --global init.templatedir ~/.git-templates
to configure the template dir globally.
Indeed, fixed above, thx.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x and store in your global git templates dir :)
In case you don't have one, create a directory at any location you prefer (mine is
~/.git-templates
), and set is as template dir:This will auto-add the hook to all newly created/cloned repos, and on the first commit in each of them, ask you to verify your user information.
No more accidental commits with wrong name/email!