Question

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.

Était-ce utile?

La solution

(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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top