Created
May 27, 2013 09:06
-
-
Save lbj96347/5655990 to your computer and use it in GitHub Desktop.
Git_Hooks_For_Auto_Deploy
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 | |
# | |
# git autodeploy script when it matches the string "[deploy]" | |
# | |
# @author cashlee | |
# @link http://cashlee.info | |
# @version 0.1 | |
# | |
# Usage: | |
# 1. put this into the post-receive hook file itself below | |
# 2. `chmod +x post-recive` | |
# 3. Done! | |
# Check the remote git repository whether it is bare | |
IS_BARE=$(git rev-parse --is-bare-repository) | |
if [ -z "$IS_BARE" ]; then | |
echo >&2 "fatal: post-receive: IS_NOT_BARE" | |
exit 1 | |
fi | |
# Get the latest commit subject | |
SUBJECT=$(git log -1 --pretty=format:"%s") | |
# Deploy the HEAD sources to publish | |
IS_PULL=$(echo "$SUBJECT" | grep "\[deploy\]") | |
if [ -z "$IS_PULL" ]; then | |
echo >&2 "tips: post-receive: IS_NOT_PULL" | |
exit 1 | |
fi | |
# Check the deploy dir whether it exists | |
DEPLOY_DIR=/var/test-hooks/ | |
if [ ! -d $DEPLOY_DIR ] ; then | |
echo >&2 "fatal: post-receive: DEPLOY_DIR_NOT_EXIST: \"$DEPLOY_DIR\"" | |
exit 1 | |
fi | |
# Check the deploy dir whether it is git repository | |
# | |
#IS_GIT=$(git rev-parse --git-dir 2>/dev/null) | |
#if [ -z "$IS_GIT" ]; then | |
# echo >&2 "fatal: post-receive: IS_NOT_GIT" | |
# exit 1 | |
#fi | |
# Goto the deploy dir and pull the latest sources | |
cd $DEPLOY_DIR && touch remote-test.txt | |
#u can do anything u want here.such as push a notification to your iPhone :-) | |
#env -i git reset --hard | |
#env -i git pull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment