问题
I have setup push-to-deploy with my production server by setting up a --bare directory at /home/ubuntu/push-to-deploy/test.git, using that as my remote and adding a hooks/post-receive inside the --bare looking like this:
#!/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 pushing to this new remote from my localhost. The post-receive script executes as it should and the content updates are reflected in the /var/www/test directory as they should be. The only thing is that my git log inside /var/www/test is not matching my localhost at all. Is this normal behavior of --work-tree? If so, what can I do to retain this push-to-deploy functionality and still have my git log copied over to the production directory as well as the content?
Also
When my content copies into the production directory (/var/www/test) all the file ownerships are overrode to ubuntu:ubuntu which makes the www-data not be able to do its thing. I put a line in my post-receive to update the ownership after each receive but is there another way (a better way) to do this?
UPDATE
The way to ensure that www-data is retained as the group is to set the directory's guid like this:
chmod -R g+s /var/www/test
This will set it to whatever the current group of the directory is, so if you want it to be www-data then make sure you set the group to www-data before you issue that command.
Thanks
回答1:
You can set the environment variable GIT_DIR to /home/ubuntu/push-to-deploy/test.git and:
- do your
git --work-tree=/var/www/test/ checkout -f $branch - or do your
git login/var/www/test/
In both case, the right index will be taken into account.
The OP sadmicrowave confirms in the comments:
just did a
chmod -R g+s /var/www/testand it is working now.
来源:https://stackoverflow.com/questions/23048155/git-logs-not-matching-when-setting-work-tree-with-push-to-deploy-post-receive