【问题标题】:Git Post-Receive Hook not being activatedGit Post-Receive Hook 未激活
【发布时间】:2013-01-11 09:37:00
【问题描述】:

我的 EC2 Amazon Linux 开发服务器上有一个 git 存储库。我正在使用 SSH 从笔记本电脑上的本地 git 存储库推送更改。

我已确认推送工作正常,因为我的本地 repo 的内容已镜像到开发服务器上。但是,我的接收后挂钩似乎没有触发。因为代码没有被检出到我的 html 目录中。

我什至尝试过使用 echo 命令来至少确认钩子正在触发,但除了本地端推送的结果外,命令行中没有反馈。

#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b7$
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".

#. /usr/share/git-core/contrib/hooks/post-receive-email
GIT_WORK_TREE=/var/www/html sudo git checkout -f

【问题讨论】:

  • 请注意:sudo 在这里真的是个坏主意。您应该调整工作树中的权限,让运行 git 的用户处理结帐。
  • 是的,它正在往墙上扔东西,看看它是否卡住了。
  • 我也有和你一样的问题。你解决了吗?
  • 我做了,但我现在不确定我到底做了什么。

标签: git


【解决方案1】:

sudo 可能不会保留GIT_WORK_TREE 环境变量——它经常被配置为为其运行的命令提供一个净化环境,尤其是当它们以root 运行时。 git 有一些命令行参数(特别是--git-dir--work-tree)可以完成与环境变量相同的任务。在这种情况下,您可能需要使用它们。

【讨论】:

  • 我已经尝试了另一个不需要使用 SUDO 的目录,并且得到了相同的结果。我什至不确定钩子是否正在触发,因为当我使用 echo 命令时没有输出。
  • 您是否按照评论中的建议重命名了挂钩脚本?这似乎很明显,但值得一问......另外,脚本是否设置为可执行?
  • 我已经删除了整个 checkout 命令并用一个简单的 echo 语句替换它,并且我确实使用 chmod +x 将其设置为可执行文件。 -rwxrwxr-x 1 ec2-user ec2-user 579 Aug 21 17:45 post-receive
【解决方案2】:

我不知道这是否可以帮助您解决云服务器问题,但我必须手动编辑 /etc/fstab 文件。我的 /srv/git 文件夹被符号链接到一个硬盘驱动器,该硬盘驱动器是通过 fstab 文件使用“noexec,user”命令安装的。将其更改为“默认值”终于解决了我的问题。我花了8个小时才弄明白。 你也可以试试

$cd /path/to/.git/hooks
$sudo chown git:git post-receive

用于接收后的文件。

【讨论】:

    【解决方案3】:

    试试这个:

    1. 不要忘记带有 --shared 选项的 init repo:

      $ git init --shared --bare repo/html.git

      $ sudo chgrp -R git repo/html.git

      $ sudo usermod -a -G git www-data

    2. 将 Git 用户添加到 sudoers(允许 www-data 用户不通过):

      $ sudo visudo

      默认值:git !authenticate

      git ALL=(www-data) NOPASSWD: /usr/bin/git

    3. 我们的单行post-receive hook:

      sudo -u www-data git --git-dir=/home/git/repo/html.git/ --work-tree=/var/www/html checkout -f

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 2014-06-02
      • 2013-07-17
      • 1970-01-01
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      相关资源
      最近更新 更多