Last active
October 27, 2020 08:55
-
-
Save kuronekomichael/6710402 to your computer and use it in GitHub Desktop.
git clone元のサーバによって、user.nameやuser.emailを切り替えるフックスクリプト git clone hook post checkout
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/sh | |
# post-checkout | |
# ============= | |
# arguments | |
# $1: ref of the previous HEAD e.g.) 0000000000000000000000000000000000000000 | |
# $2: ref of the new HEAD e.g.) 959224d097072c8a5640fee31bac7325710eada1 | |
# $3: flag = ブランチをチェックアウトした場合=1, ファイルをチェックアウトした場合=0 | |
# `git clone`時だけ処理をしたいので、通常の`git checkout`時には何もしない | |
if [ "$1" != "0000000000000000000000000000000000000000" -o "$3" != "1" ]; then | |
exit | |
fi | |
GIT_REMOTE=`git remote -v` | |
echo "" | |
if [[ "$GIT_REMOTE" =~ "@github.com:" ]]; then | |
echo "\033[32m ✓ checkout from github.com\033[0m" | |
git config --local user.name "<username for github>" | |
git config --local user.email "<email for github>" | |
elif [[ "$GIT_REMOTE" =~ "@bitbucket.org:" ]]; then | |
echo "\033[32m ✓ checkout from bitbucket\033[0m" | |
git config --local user.name "<username for bitbucket>" | |
git config --local user.email "<email for bitbucket>" | |
else | |
echo "\033[31m ✗ unmatched\033[0m" | |
fi | |
git config --local -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
事前に実行可能に設定しておくことを忘れずに。
例a). プロジェクト毎にhookを設定する
例b). ユーザ毎にhookを設定する
例c). グローバルにhookを設定する