Created
January 3, 2012 22:59
-
-
Save khalsah/1557423 to your computer and use it in GitHub Desktop.
Experimental git sync & deploy hooks
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 | |
LOCAL_BRANCH="master" | |
LIVE_BRANCH="live" | |
REMOTE_NAME="deploy" | |
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" | |
git push ${REMOTE_NAME} ${LOCAL_BRANCH}:master | |
git pull ${REMOTE_NAME} ${LIVE_BRANCH} | |
git push ${REMOTE_NAME} ${LOCAL_BRANCH}:master | |
fi |
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 | |
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 |
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 | |
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 |
Added [ -f /usr/local/bin/growlnotify ] && growlnotify -s -m "Project has been Deployed" || echo "Project has been deployed"
for Mac OSX Growl Notification. Quick check to see if Growl is Installed (in the proper place) then notifies that the project has been synchronized with a fall-back using echo
. Nice for those large commits that take a little while. I'll jump over to another window or screen and work on something-- then am notified that the Sync was complete.
It's all about the simple things in life.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot to ask you today. When I am setting up these 'web' or 'deploy' repositories on the client's server (to deploy too), I do a basic
git init
since we discussed not usinggit --bare init
on these repositories. I've had to addgit config receive.denycurrentbranch=ignore
to each repository. That makes sense, right? If I don't add that, the push does not work at all because of the fast-forward. (Correct, or am I thinking about that the wrong way?). Only reason I ask, is because that's how I am setting up a new repo right now.That all makes sense, right?