Last active
August 29, 2015 14:19
-
-
Save mogproject/f6c18bc3e4478a50034c 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/bash | |
GIT=/usr/local/bin/git | |
SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd -P ) | |
if [ "$1" = "clone" ]; then | |
origin_url="$2" | |
else | |
# check if current directory is under git repository | |
origin_url=$("$GIT" config --get remote.origin.url) || { | |
"${GIT}" "$@" | |
exit $? | |
} | |
fi | |
# definitions | |
case ${origin_url} in | |
[email protected]:your-company/*) | |
readonly user_name='Your name 1' | |
readonly user_email='[email protected]' | |
readonly git_ssh='ssh-yourname-1' | |
;; | |
*) | |
readonly user_name='Your name 2' | |
readonly user_email='[email protected]' | |
readonly git_ssh='ssh-yourname-2' | |
;; | |
esac | |
# check name and email | |
if [ "$1" != "clone" ]; then | |
current_name=$("$GIT" config --get user.name) || { | |
echo "Failed to get user name. Aborted." | |
exit 1 | |
} | |
current_email=$("$GIT" config --get user.email) || { | |
echo "Failed to get user email. Aborted." | |
exit 1 | |
} | |
if [ "${current_name}" != "${user_name}" ]; then | |
echo "Setting user name: \"${GIT}\" config user.name \"${user_name}\"" | |
"${GIT}" config user.name "${user_name}" | |
fi | |
if [ "${current_email}" != "${user_email}" ]; then | |
echo "Setting user email: \"${GIT}\" config user.email \"${user_email}\"" | |
"${GIT}" config user.email "${user_email}" | |
fi | |
fi | |
# launch git command | |
GIT_SSH="${SCRIPT_DIR}/../ssh/${git_ssh}" "${GIT}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment