Last active
August 29, 2015 13:56
-
-
Save tkengo/9320008 to your computer and use it in GitHub Desktop.
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
#/bin/sh | |
template_dir=$HOME/.git_template | |
hook_dir=$template_dir/hooks | |
pre_push=$hook_dir/pre-push | |
hook_script='[ "$(git rev-parse --abbrev-ref HEAD)" = "master" ] && echo "You cant push the master branch to the remote" && exit 1' | |
current_template_dir="$(git config -l | grep init.templatedir)" | |
current_template_dir=${current_template_dir#init.templatedir=} | |
if [ -n "$current_template_dir" -a "$current_template_dir" != "$template_dir" ]; then | |
mkdir -p $current_template_dir/hooks | |
pre_push=$current_template_dir/hooks/pre-push | |
else | |
mkdir -p $hook_dir | |
git config --global init.templatedir $template_dir | |
fi | |
if [ -e $pre_push ]; then | |
[ -n "$(grep 'You cant push the master branch to the remote' $pre_push)" ] && exit 1 | |
fi | |
echo $hook_script >> $pre_push | |
echo exit 0 >> $pre_push | |
chmod +x $pre_push | |
echo OK, all set. | |
echo 'All you need to do is that executing "git init" in your existing git project directory.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment