0

git post-update 挂钩有一个奇怪的问题。我在我的服务器 ( /var/www/vhosts/git/master.git) 上创建了存储库,并在此存储库中添加了一个更新后挂钩,其中包含以下代码:

#!/bin/sh

echo $1
echo "*UPDATE*"

case " $1 " in
*'refs/heads/master'*)
    GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f
    echo
    echo "Master was updated!"
    echo
    ;;
esac

case " $1 " in
*'refs/heads/sandbox'*)
GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f
    echo
    echo "Sandbox was updated!"
    echo
    ;;
esac

我确保这个文件是可执行的。然后我在我的机器上创建了一个本地存储库,使用:

$ mkdir website && cd website
$ git init
$ echo 'Testing.' > index.html
$ git add index.html
$ git commit -q -m "Initial commit"
$ git remote add web ssh://username@website.com/var/www/vhosts/website.com/git/master.git
$ git push web +master:refs/heads/master

无论出于何种原因,第一次推送都可以正常工作 - <code>/var/www/vhosts/website.com/sandbox.website.com 使用索引文件进行更新 - 但随后的推送都不起作用。post-update我从“Master 已更新!”的钩子中得到响应。但该目录实际上并没有得到更新。

建议?

4

1 回答 1

0

您似乎有权限问题。查看路径上的权限/var/www/*并确保您的 git 用户有权读取/写入/删除文件。

我使用了一种更简单的技术(这里有一个详细的脚本),它允许我将我的服务器用作带有 gitolite 的 git 服务器并在推送时部署,而无需在/var/www/myproject路径上克隆存储库。它对我git 1.7.9有用Ubuntu 12.04.1 LTSApache/2.2.22

  1. 在服务器上创建存储库:

    mkdir myproject.git && cd myproject.git
    git init --bare
    
  2. 配置存储库:

    git config core.worktree /var/www/myproject
    git config core.bare false
    git config receive.denycurrentbranch ignore
    
  3. 编辑或创建hooks/post-receive并使其可运行

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

这是文件内容:

#!/bin/sh
git checkout -f

您已准备好进行推送并使其正常工作。

我的 git 用户被调用git,我的 apache 使用了该ubuntu用户。我必须编辑 apache 配置/etc/apache2/conf.d/security(你也可以这样做/etc/apache2/http.conf)以包括:

User git
Group git

现在我/var/www/myproject在推送上部署所有文件,使用git:git用户/组创建文件,我的 apache 使用相同的用户/组运行。

现在您只需要重新启动服务器或执行service apache2 restart

于 2012-10-31T18:49:23.797 回答