Last active
December 17, 2015 09:39
-
-
Save alecthegeek/5589064 to your computer and use it in GitHub Desktop.
Wraps the git init or git clone commands to double check the users's email address.
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 | |
# Wrapper script for git | |
if [[ -x /usr/local/bin/git ]] ; then | |
GIT=/usr/local/bin/git #Set for your environment" | |
elif [[ -x /usr/bin/git ]] ; then | |
GIT=/usr/bin/git #Set for your environment" | |
else | |
echo Git not installed correctly? | |
exit | |
fi | |
# If using git svn then will see of the tortoise commit template is in use an configure | |
# if needed | |
# After clone or init allows user to check the email address used for repo commits | |
# NB Will always set the email address in the current repo | |
# User is prompted to select an email address from the user.emaillist config option | |
# to set use a command similiar to | |
# 'git config --global user.emaillist "me@personal.address me@work.address me@coolOSS.project' | |
# return code is the status of the real git command run | |
if $GIT svn info --url > /dev/null 2>&1 && [[ $1 == "ci" || $1 == "commit" ]] && | |
$GIT svn propget tsvn:logtemplate > /dev/null ; then | |
templatefile=/tmp/$$template | |
$GIT svn propget tsvn:logtemplate > $templatefile | |
$GIT config commit.template $templatefile | |
fi | |
$GIT "$@" | |
return=$? | |
[[ $1 == "svn" ]] && shift | |
if [[ $1 == "init" || $1 == "clone" ]] ; then | |
[[ -d ${@: -1} ]] && cd ${@: -1} # Did the repo get created in a subdir? | |
if ! $GIT rev-parse --git-dir 2> /dev/null ; then | |
x=${@:-1}; x1=${x##*/}; td=${x1%%.git} | |
if [[ -d $td ]] ; then | |
cd $td | |
else | |
echo Unable to configure repo any further in $td | |
exit $return | |
fi | |
fi | |
email=$($GIT config --get user.email) | |
echo Email address for you on this local repo is $email | |
emaillist=$($GIT config --global --get user.emaillist) | |
if [[ -z $emaillist ]] ; then | |
echo user.emaillist not set \~/.gitconfig. Please enter an alternative if wanted | |
read -p 'any other value (that does not contain a "@") will leave it unchanged: ' | |
if [[ $REPLY == *@* ]] ; then | |
$GIT config user.email $REPLY | |
echo repo email address set to $($GIT config --null --get user.email) | |
else | |
echo repo email address unchanged | |
fi | |
exit $return | |
fi | |
echo Please select an email address for this repo or type in an alternative. | |
echo 'any other value (that does not contain a "@") will leave it unchanged: ' | |
select e in $emaillist ; do | |
if [[ $REPLY == *@* ]] ; then | |
$GIT config user.email $REPLY | |
elif [[ $e == *@* ]] ; then | |
$GIT config user.email $e | |
fi | |
echo repo email address set to $($GIT config --get user.email) | |
exit $return | |
done | |
fi | |
[[ -n $templatefile ]] && git config --unset commit.template | |
exit $return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment