I am developing a web application using Gitosis (Debian Lenny) that I want to be able to push to different remote repos/locations thus allowing a "bleeding-edge", "release-candidate", & "production" version of the application with mirrored physical web directories and codebase. I would prefer each directory to have a branch of the application. So one repository, three "live" versions.
I am new to Git so there's probably a better solution but what i've come up w/ so far is either finding a way to attach hooks to branches (which I haven't found) or to write a hook that will filter for which branch is being committed.
My question is on how to set up a post-update hook that will check the committed branch, set a variable for the directory based on that branch, and literally copy the codebase into that directory where it can be instantly accessible over HTTP?
git rev-list --branches --pretty=oneline --max-count=1
will return something like:
cc5112ba59bc82f2e847ac264317c062ce80f69f test commit
but i need the name of the branch itself like "experimental" or "master".
So basically I'm looking for something like:
1) Get name of branch that was just committed (e.g. "master", "experimental") into a string
2) Use Bash case to declare what directory to use
3) Run something like "git archive --format=tar HEAD | (cd $LOCATION && tar xf -)" where location is what was returned from case.
I thought I was getting close with the following but realized it didn't return the branch name but the commit message instead:
#!/bin/sh
# Get substr from "sha1[space]commit-msg"
BRANCH=$(git rev-list --pretty=oneline --branches --max-count=1 | awk '{split($0,array," ")} END{print array[2]}')
case $BRANCH in
"experimental")
dir="/home/APP_NAME/experimental"
;;
"master")
dir="/home/APP_NAME/production"
;;
esac
# move to location and copy files
git archive --format=tar HEAD | (cd $loc && tar xf -)
I did realize that if I always put the branch as the first part of the commit I could accomplish something like this but I really don't want to worry about it.
Any help would be appreciated. Thanks in advance!