Last active
August 29, 2015 13:55
-
-
Save pospi/8746364 to your computer and use it in GitHub Desktop.
A generic git post-receive hook for auto-deploying applications when pushed to.
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 | |
#------------------------------------------------------------------------------# | |
# CONFIGURATION | |
# You will need the following variables set in the git repository to deploy from: | |
# git config --bool receive.denyCurrentBranch false | |
# git config --bool core.bare false | |
# git config --path core.worktree [DEPLOYMENT_DIR] | |
#------------------------------------------------------------------------------# | |
# Read standard input to work out the branch (or tag) we've just pushed | |
while read oldrev newrev refname | |
do | |
DEPLOY_BRANCH=`echo $refname | cut -d/ -f3` | |
done | |
echo "Pushed branch $DEPLOY_BRANCH" | |
# Setup environment for git | |
unset GIT_DIR | |
DEPLOY_DIR=`git config --get core.worktree` | |
# Check required directories are present | |
if [ ! -d "$DEPLOY_DIR" ]; then | |
echo "Could not locate deployment directory $DEPLOY_DIR" | |
exit 1 | |
fi | |
# move into working copy | |
cd $DEPLOY_DIR | |
# Check for local modifications, abort and notify if found | |
git diff --quiet | |
EXIT_CODE=$? | |
if [[ $EXIT_CODE -ne 0 ]]; then | |
echo "Local changes to tracked files detected, aborting deployment. Files changed:" | |
git diff --name-only | |
exit 1 | |
fi | |
# Run the deployment of the main repo | |
git checkout -f $DEPLOY_BRANCH | |
# Run the deployment for submodules | |
git submodule update --init --recursive --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment