Experimental git sync & deploy hooks
#!/bin/sh
cd "$(dirname $0)/.."
export GIT_DIR="."
export GIT_WORK_TREE=".."
if [ "$(git symbolic-ref -q HEAD)" != "refs/heads/live" ]; then
echo "Not on live, not syncing changes"
exit 1
elif ! git diff-index --exit-code --quiet --cached HEAD --; then
echo "Changes exist in index, not syncing"
exit 1
elif [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 0
else
git add --all $GIT_WORK_TREE
git commit -m "$(date "+SYNC %F %T")"
exit 0
fi
#!/bin/sh
cd "$(dirname $0)/.."
export GIT_DIR="."
export GIT_WORK_TREE=".."
if [ "$(git symbolic-ref -q HEAD)" != "refs/heads/live" ]; then
echo "Not on live, not deploying"
exit 1
elif ! ./hooks/sync; then
echo "Sync failed"
exit 1
elif ! git merge --ff-only "refs/heads/master"; then
echo "New changes on live, not deploying"
exit 1
else
echo "Changes deployed"
exit 0
fi
#!/bin/sh
LOCAL_BRANCH="master"
LIVE_BRANCH="live"
REMOTE_NAME="web"
# Remote Name is your Deploy Branch. Default is web. Live Branch is the branch on the Remote Server that is merged with master to synchronize changes
if [ "$(git symbolic-ref -q HEAD)" != "refs/heads/${LOCAL_BRANCH}" ]; then
echo "Not on ${LOCAL_BRANCH}, not deploying"
exit 1
else
echo "Syncing and deploying"
echo "Pushing to ${REMOTE_NAME} on ${LOCAL_BRANCH} branch..."
git push ${REMOTE_NAME} ${LOCAL_BRANCH}:master
echo "Pulling from ${REMOTE_NAME}..."
git pull ${REMOTE_NAME} ${LIVE_BRANCH}
echo "Pushing to ${REMOTE_NAME}..."
git push ${REMOTE_NAME} ${LOCAL_BRANCH}:master
fi
[ -f /usr/local/bin/growlnotify ] && growlnotify -s -m "Project has been Deployed" || echo "Project has been deployed"
exit