来自 PHP 的 git 提交将不起作用


git commit from php won't work

我有一个简单的php脚本,可以在本地git存储库上执行git提交操作。它曾经工作得很好,但自从我搬到新服务器后,它就停止了工作。exec 响应代码为 128,输出为空。

我的第一个想法是目录权限或所有权,但我已经尝试了一切,但没有帮助。任何人都知道可能是什么问题或更好地识别错误的方法?

这是重现问题的测试代码:

$repoName = 'test';
$dirpath = __DIR__;
if (! file_exists($dirpath . DIRECTORY_SEPARATOR . $repoName)) {
    mkdir($dirpath . DIRECTORY_SEPARATOR . $repoName, 0777, true);
}
exec('git init ' . $repoName);
$dirpath .= DIRECTORY_SEPARATOR . $repoName;
chdir($dirpath);
file_put_contents($dirpath. DIRECTORY_SEPARATOR . '.gitkeep', '');
file_put_contents($dirpath. DIRECTORY_SEPARATOR . 'realFile.txt', 'this is a test');
exec('git add -A');
exec('git commit -a --author="user <user>" -m "test message"', $output, $returnCode);
echo "return code $returnCode<br/>";
echo "output:<br/>";
var_dump($output);

在 shell 命令末尾使用 2>&1 将 stderr 重定向到 stdout。