How can I change the git post-update hook to activate on only one (master) branch?

I have installed a bare repo on my website and cloned a repo that will update whenever changes are pushed to the bare repo. The cloned repo on the web host is essentially "production" and is located in the public_html directory. I followed the instructions on this site closely:

http://www.ibm.com/developerworks/web/library/wa-git/

He instructed me to do the "post-update" hook in the main repo:

#!/bin/bash 
WEB_DIR="<web_dir>"
export GIT_DIR="$WEB_DIR/.git"
pushd $WEB_DIR > /dev/null
git pull
popd > /dev/null

      

This is a great VCS solution if I'm only working on the master branch.

When I'm at location A, I want to clone the bare repo, start working on the "newstuff" branch, commit the changes, and then push it to the bare repo so that if I go to location B I can clone the bare repo and have access to "beginners". But I don't want "production" to be updated via a post-update script.

Is there a way to change my post-update script just to do this when the update is done on the master branch?

+2


source to share


1 answer


The updated refs are passed to the hook as arguments. This means that you can test the master with case

:

case " $* " in
*' refs/heads/master '*)
        # Do stuff
        ;;
esac

      



By the way, git pull

the server will only fetch other branches, but will not change your working directory unless the master has been updated, so this is not necessary (unless you are concerned about performance maybe).

Also see the official documentation about the hook: http://schacon.github.com/git/githooks.html#post-update

+6


source







All Articles