git logs not matching when setting --work-tree with push-to-deploy post-receive hook

纵饮孤独 提交于 2019-12-08 08:32:20

问题


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 log in /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/test and it is working now.



来源:https://stackoverflow.com/questions/23048155/git-logs-not-matching-when-setting-work-tree-with-push-to-deploy-post-receive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!