Deploying site with Git: post-update hook works first time, then never again

后端 未结 1 684
长发绾君心
长发绾君心 2021-01-28 12:10

Having a strange issue with a git post-update hook. I created repository on my server (/var/www/vhosts/git/master.git) and in this repository added a post-update ho

相关标签:
1条回答
  • 2021-01-28 12:33

    You seem to have have a permission issue. Take a look on the permissions on the/var/www/* path and ensure that your git user has permission to read/write/delete on the files.

    I have used a much simpler technique (here is a detailed script) that allowed me to use my server as git server with gitolite and deploy on push without having to clone the repository on the /var/www/myproject path. It is working for me on git 1.7.9 and Ubuntu 12.04.1 LTS with Apache/2.2.22.

    1. Create your rpository on the server:

      mkdir myproject.git && cd myproject.git
      git init --bare
      
    2. Configure the repository:

      git config core.worktree /var/www/myproject
      git config core.bare false
      git config receive.denycurrentbranch ignore
      
    3. Edit or create the hooks/post-receive and make it runnable

      touch hooks/post-receive
      chmod u+x hooks/post-receive
      

    Here is the file content:

    #!/bin/sh
    git checkout -f
    

    You are ready to do a push and have it working.

    My git user is called git and my apache used the ubuntu user. I had to edit the apache configuration on /etc/apache2/conf.d/security (you can do it on /etc/apache2/http.conf also) to include:

    User git
    Group git
    

    Now my /var/www/myproject deploys all the files on push, creating the files with git:git user/group and my apache uses the same user/group to run.

    Now you just have to restart your server or do a service apache2 restart

    0 讨论(0)
提交回复
热议问题