Skip to content

Instantly share code, notes, and snippets.

@egdelwonk
Created February 27, 2013 22:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egdelwonk/5052319 to your computer and use it in GitHub Desktop.
Save egdelwonk/5052319 to your computer and use it in GitHub Desktop.
Setup post-receive hooks to checkout code to a webroot folder when pushing to a remote repo
STAGE_PATH=$1
REPO_PATH=$2
clear
echo 'Git Setup'
echo ''
echo '+--------------------------------------------------------+'
echo '| Setting up deployment repo |'
echo '|--------------------------------------------------------|'
printf "| Repo Dir: "
printf '%42s' "$REPO_PATH "
printf "\n| Staging Dir: "
printf '%42s' "$STAGE_PATH "
echo '| |'
echo '+--------------------------------------------------------+'
echo ''
echo ''
echo ' + creating staging directory: ' $STAGE_PATH
mkdir $STAGE_PATH
echo '...done'
echo ''
echo ' + creating repository directory: ' $REPO_PATH
mkdir $REPO_PATH
echo '..done'
echo ''
cd $REPO_PATH
echo ' + intializing repository with working path: ' $STAGE_PATH
git --git-dir=. --work-tree=$STAGE_PATH init
git config receive.denycurrentbranch ignore
echo '...done.'
echo ''
echo ''
echo '+--------------------------------------------------------+'
echo '| Creating post receive hooks |'
echo '+--------------------------------------------------------+'
rm -rf hooks/post-receive
echo "#!/bin/sh" >> hooks/post-receive
echo "export GIT_DIR=$(pwd)" >> hooks/post-receive
echo "cd $STAGE_PATH" >> hooks/post-receive
echo "git checkout -f master" >> hooks/post-receive
echo "git submodule init" >> hooks/post-receive
echo "git submodule update" >> hooks/post-receive
echo '...done'
echo ''
echo ''
echo '+--------------------------------------------------------+'
echo '| Updating callback script permissions |'
echo '+--------------------------------------------------------+'
chmod +x hooks/post-receive
echo '...done'
echo ''
echo ''
echo '+--------------------------------------------------------+'
echo '| SETUP COMPLETE |'
echo '+--------------------------------------------------------+'
echo ''
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment