Reputation: 5185
I've setup /var/www/website
as a (non-bare) repo, and have my post-update hook of my bare repo:
#!/bin/sh
echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo
cd /var/www/website || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
Because I wanna see changes on website right after push.
But if I create remote branch, which works with it in my local repo and then do commit and push changes in it, I can't see them on the website (I always see master).
Is there any way to do a checkout in remote (non-bare) repo?
Upvotes: 1
Views: 151
Reputation: 487755
The post-update hook gets the names of all the references that have been updated. These will be positional parameters ($1
, $2
, and so on). You will have to decide what to do with each one.
For instance, this somewhat silly post-update script:
#! /bin/sh
for ref do
case $ref in
refs/heads/*) echo "a branch ($ref) was updated";;
refs/tags/*) echo "a tag ($ref) was updated";;
*) echo "something I don't understand ($ref) was updated";;
esac
done
simply prints out the full names of everything that was updated.
Making it less silly, let's say we want to catch branch updates and do something useful with them. Replace the first echo with something more complex:
refs/heads/*) branch_update $ref;;
Of course we have to define a branch_update function. Here's the new script (which still does not do anything but has obvious places in which to do something):
#! /bin/sh
branch_update() {
local shortname=${1#refs/heads/}
echo "branch $shortname is being updated"
case $shortname in
master) echo "master is updated, do something";;
work) echo "work branch is updated, do something else";;
*) echo "it's not a magic branch, do nothing";;
esac
}
for ref do
case $ref in
refs/heads/*) branch_update $ref;;
refs/tags/*) echo "a tag ($ref) was updated";;
*) echo "something I don't understand ($ref) was updated";;
esac
done
Aside: the way your question is phrased suggests you're not quite "thinking in git" as it were. :-) When you do a push (from your own copy of some repo to some other copy, bare or not, of some repo), you may find the results more understandable if you change your point of view. You can start by thinking "I'm pushing" but then you can imagine the remote repo as some other actor, let's give him a name and call him "Bob", and think what Bob is seeing. From Bob's point of view, instead of "Yekver is pushing stuff", Bob thinks: "I, Bob, am getting something from that Yekver guy over there and putting it into my repo. I'm adding tag refs/tags/v1.1, and I'm taking some commits and putting them in my refs/heads/master, and I'm taking some more commits and putting them in my refs/heads/devel-xyz."
The key concept here is that in terms of what git does, everything is local. From Bob's point of view, Bob's repo is local. Some guy named Yekver may have a repo based on that, but Bob's copy is Bob's. Bob does local things with Bob's local repo, and when you're working within those hook scripts, you're "being Bob".
Upvotes: 1