Git Logs don't match on setup - work tree with push-to-deploy post-receive hook
I have a push-to-deploy setup with my production server, setting up the directory --bare
to /home/ubuntu/push-to-deploy/test.git
, using this as my remote and adding hooks/post-receive
inside --bare
like below:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "production" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/test/ checkout -f $branch
sudo chown -R ubuntu:www-data /var/www/test
echo 'Changes pushed to Amazon EC2 PROD.'
fi
done
This works great when clicking on this new remote access from my localhost. post-receive
The script is executed as it should and the content updates are reflected in the directory /var/www/test
as they should. The only thing mine git log
inside /var/www/test
doesn't match my localhost at all. Is this normal behavior --work-tree
? If so, what can I do to keep this functionality push-to-deploy
and still have my git log copied to the production directory as well as the content?
AND
When my content is copied to the production directory ( /var/www/test
), all file owners are overridden ubuntu:ubuntu
, making it www-data
unable to complete my task. I put a string in mine post-receive
to update the ownership after every get, but is there any other way (better way) to do this?
UPDATE
A way to ensure that www-data
persists as the group is to set the guid directory like this:
chmod -R g+s /var/www/test
This will set it to any current directory group, so if you want it to be www-data
, make sure you set the group to www-data
before you run this command.
thank
source to share
You can set your environment variable GIT_DIR
to /home/ubuntu/push-to-deploy/test.git
and:
- make your
git --work-tree=/var/www/test/ checkout -f $branch
- or run
git log
in/var/www/test/
In both cases, the right index is taken into account.
OP sadmicrowave confirms in the comments :
just did and now it works.
chmod -R g+s /var/www/test
source to share