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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?