duanbushi1867 2013-12-05 20:41
浏览 49
已采纳

PHP Git Hook在测试执行时直接工作,但在通过git执行时不工作

I created the following git hook to automate some tasks for me and to pipe it back down when I push a commit to my server. The code works fine when I run it directly. When the git push pushes to the server and the server executes the hook it says

remote: Deployment [BETA]: updating.
remote: git fatal not a git repository.
remote: Deployment [BETA]: complete.
remote: git fatal not a git repository.

My hook code is:

#!/usr/bin/php
<?php

chdir("/var/www");

echo "Deployment [BETA]: updating." . PHP_EOL;
exec("git pull");
echo "Deployment [BETA]: complete." . PHP_EOL;

// Get the last commit message.
$log = shell_exec("git log -n 1 HEAD");

if (stripos($log, "[trigger:composer]"))
{
    echo "Composer: starting." . PHP_EOL;
    system("php /home/root/bin/composer.phar update");
    echo "Composer: completed." . PHP_EOL;
}

if (stripos($log, "[trigger:phpunit]"))
{
    system("./vendor/bin/phpunit");
}

If anyone can help me that would be really appreciated.

  • 写回答

1条回答 默认 最新

  • dsfd3546 2013-12-05 21:25
    关注

    (From #git) The issue was actually that within the context of the hook GIT_DIR and GIT_WORK_TREE are set appropriately for the repository you're working with. If you're going to cd within the hook script then you should generally set GIT_DIR and GIT_WORK_TREE appropriately: either unset them if you're moving to a Git working tree, or set them to point to the appropriate working tree and repository directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作