Skip to content

Instantly share code, notes, and snippets.

@gravitano
Last active August 29, 2015 14:24
Show Gist options
  • Save gravitano/e70b7af17212de979b6d to your computer and use it in GitHub Desktop.
Save gravitano/e70b7af17212de979b6d to your computer and use it in GitHub Desktop.
Git Hook Script
#!/bin/sh
#
## store the arguments given to the script
read oldrev newrev refname
# The deployed directory (the running site)
DEPLOYDIR=/root/web/domain.com
# Repository Directory
REPODIR=/root/repo/domain.git
## Where to store the log information about the updates
LOGFILE=$REPODIR/post-receive.log
## Record the fact that the push has been received
echo -e "Received Push Request at $( date +%F )" >> $LOGFILE
echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE
## Run Hook : Before
BEFORE_SCRIPT=$DEPLOYDIR/.hooks/before.sh
if [ -f $BEFORE_SCRIPT ]; then
echo "Running Hook: Before"
. $BEFORE_SCRIPT
fi
## Update the deployed copy
echo "Starting Deploy" >> $LOGFILE
echo "- Deploying"
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
echo "- OK"
## Run Hook : After
AFTER_SCRIPT=$DEPLOYDIR/.hooks/after.sh
if [ -f $AFTER_SCRIPT ]; then
echo "Running Hook: After"
. $AFTER_SCRIPT
fi
echo "- Done"
echo "Finished Deploy" >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment