shell_exec
如果命令失败将返回NULL
。这几乎肯定会发生......问题是为什么。您无法找到使用shell_exec
的地方。
我推荐使用exec,所以你至少可以弄清楚调用的状态以及出错的地方。
http://www.php.net/manual/en/function.exec.php
这将允许你设置一些增值经销商将与系统的内部操作系统调用的返回值来填充。
$shell_output = array();
$status = NULL;
if($_GET['action']=='add'){
$output = shell_exec('git add *',$shell_output,$status);
print_r($shell_output)
print_r($status);
}
if($_GET['action']=='commit'){
$output = shell_exec('git commit -m "'.$_POST["txt"].'" ',$shell_output,$status);
print_r($shell_output)
print_r($status);
}
我的猜测是你的权限有问题。 git中的commit
需要对该目录的“.git”文件夹具有写入权限。
此外,请确保您在正确的目录下操作!运行PHP实例的apache用户可能已经或可能不会已经cd
编辑到repo所在的正确文件夹。您可能需要将cd path_to_repo && git commit
添加到您的命令中才能首先移至正确的目录。我首先用绝对路径进行调试。
只是一个建议的话......如果你试图建立一个基于PHP的git客户端,你将不得不处理大量的失败案例,其中一个很容易在这段代码中看到。 ..没有新文件被修改时尝试提交。我会鼓励你看看社区的解决方案,如果你需要与这些案件被关注:
Is there a good php git client with http support?
我假设你使用的是Apache?你的apache用户运行在什么特权级别? Git涉及写入隐藏的'.git'文件夹。没有适当的写入权限,它将失败。 – DeaconDesperado 2012-07-19 15:43:41