I'm trying to deploy my website using git/gitolite.
I've created a remote repository, I cloned it to my local machine.
I've 2 branches Master and develop.
I've created a script of post-receive hook in order to deploy each branch in the correct web directory :
/var/www/<mysite>/
for branch Master [live version]
/var/www/<mysite>/dev
for branch develop [dev version]
for that I'm using this script in .gitolite/hooks/common/post-receive
file :
#!/bin/bash
prodroot="/var/www/<mysite>"
devroot="/var/www/<mysite>/dev"
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
sudo git --work-tree=$prodroot checkout -f
sudo chown -R webuser:psacln $prodroot
else
echo "Push on dev branch"
sudo git --work-tree=$devroot checkout -f
sudo chown -R webuser:psacln $devroot
fi
done
If I use it this way, it doesn't work properly, because checkout -f
always get master branch, in other side if I use checkout -f $branch
I'm getting an error saying :
fatal: '/home/git/repositories/<mysite>.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
And every thing fall down, I'm obliged to create repositories [Using gitolite].
What I want to understand is : if it's not a git directory, why it works for checkout -f
[MASTER] and not for checkout -f $branch
[here DEVELOP] ?
Am I missing something ? Please help me.
Thank you.