php - "git pull"外部世界不工作

标签 php git github

我正在配置一个 github web hook 来调用下面的页面:

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 从外部世界联系该页面时,没有任何反应。我的日志文件中也没有错误。这是怎么回事?

最佳答案

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

<?php 

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

?>

注意:对于裸存储库,您 shell 仅传递 --git-dir 键值。

关于php - "git pull"外部世界不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21174191/

相关文章:

Github API获取特定代码行的作者/提交者

php - session_start 耗尽内存

api - 如何使用 API (curl) 编辑 github 问题? (尤其是 : close)

php - 如何在 WooCommerce 数据库中找到客户订购的产品?

git - 无法恢复的 git 推送?

git - 学习Git:跟踪与设置 Remote 的上游(-u)?

git - git中如何列出目录树的变更历史

javascript - 如何在 GitHub Pages 上托管?

php - 转换数字 |整数到单词

如果字段名是 0,PHP Mysql_fetch_array 失败