【问题标题】:"git pull" not working from the outside world“git pull”在外部世界不起作用
【发布时间】:2014-02-06 02:13:02
【问题描述】:

我正在配置一个 github 网络挂钩来调用以下页面:

github.php:

<?php 

shell_exec('git pull');

?>

我有 chmod 777 文件,甚至还有 chmod +x 它。当我从服务器调用php github.php 时,一切都很好:

remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2)
Unpacking objects: 100% (3/3), done.
From https://github.com/mynameise/Octo
   afadfb8..1ad3b76  master     -> origin/master

但是当我尝试使用 http 从外部世界联系该页面时,没有任何反应。我的日志文件中也没有错误。怎么回事?

【问题讨论】:

  • 让你的钩子把输出写到某个地方,这样你就会得到一些反馈:shell_exec('git pull 2&gt;&amp;1 &gt; hook-output.log');
  • @poke hook-output 仅在通过服务器访问时创建。通过网络访问时,甚至没有创建文件。
  • 您的网络服务器用户是否有权执行git?从localhost 通过您的网络服务器运行脚本是否有效?
  • @Chris 很好的问题。我不知道如何从具有权限的 Web 服务器用户那里检查它。坦率地说,我不知道谁是网络服务器用户:/
  • 好吧,尝试从localhost(运行 Web 服务器的机器)通过 HTTP 触发脚本将是一个不错的起点。如果可行,Web 服务器用户就可以运行 Git。

标签: php git github


【解决方案1】:

这是因为脚本没有从git仓库根目录运行,你需要指定正确的git仓库路径,直接在php代码中:

<?php 

shell_exec('git --work-tree=/full/path/to/git/repo --git-dir=/full/path/to/git/repo/.git pull');

?>

注意:对于裸存储库,您只能通过 --git-dir 键值传递。

【讨论】:

  • @Tom 输出是什么?
  • 根本没有输出
  • @Tom git --work-tree=/full/path/to/git/repo --git-dir=/full/path/to/git/repo/.git pull 在 shell 中工作吗?
  • @Tom 如果你能够在shell中运行命令,我相信问题出在php的EVN变量上,似乎找不到git app
  • 但是当我从服务器运行php github.php 时它可以工作,所以这不是问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-03
  • 2018-06-29
  • 1970-01-01
  • 1970-01-01
  • 2011-01-26
  • 2020-03-26
  • 2017-06-25
相关资源
最近更新 更多