执行git的在当前目录下的PHP文件提交 [英] Execute git commit from php file in current directory

查看:137
本文介绍了执行git的在当前目录下的PHP文件提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行此code,但它不会做任何事情。
但在放了shell_exec混帐秀--summary,当它返回混帐statuss。

I try to execute this code, but it doesn't do anything. But when put "git show --summary" in shell_exec it return git statuss.

if($_GET['action']=='add'){
    $output = shell_exec('git add *');
    echo "Add:<pre>$output</pre>";
}
if($_GET['action']=='commit'){
    $output = shell_exec('git commit -m "'.$_POST["txt"].'" ');
    echo "Commit:<pre>$output</pre>";

}

它是更多钞票从PHP犯git的,怎么样?

Is it posible to commit git from php, and how?

推荐答案

了shell_exec 是要返回 NULL 如果该命令将失败。这是几乎可以肯定发生了......问题是为什么。你是不是要能够找出使用了shell_exec

shell_exec is going to return NULL if the command fails. This is almost certainly happening... the question is why. You aren't going to be able to find out using shell_exec.

我建议,而不是使用EXEC,这样你至少可以搞清楚呼叫的状态和正在发生的事情是错误的。

I'd recommend instead using exec, so you can at least figure out the status of the call and what's going wrong.

http://www.php.net/manual/en/function。 exec.php

这将允许您设置一些增值分销商,将与该系统的内部操作系统调用的返回值进行填充。

This will allow you to setup some vars that will be populated with the return values of the system's internal os call.

$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);
}

我的猜测是,你有权限的问题。 A 提交在git的要求写入权限该目录的git的文件夹。

My guess is you have a problem with permissions. A commit in git requires write permission to that directory's '.git' folder.

此外,请确保您在正确的目录操作!正在运行PHP实例Apache用户可能会或可能不会已经 CD ED向右文件夹中的回购协议。您可能需要添加一个 CD path_to_repo和放大器;&安培; git的承诺你的命令首先移动到正确的目录。我倒是第一次调试此使用绝对路径。

Also, make sure you are operating in the proper directory! The apache user that is running the PHP instance may or may not be already cded to the right folder where the repo is. You may need to add a cd path_to_repo && git commit to your command to first move to the right directory. I'd first debug this with absolute paths.

建议只是一个字,以及...如果你想建立一个基于PHP的git客户端,你将不得不处理一吨的失败案例,其中一个很明显在这$ C $ ç...尝试当没有新的文件已被修改提交。我会鼓励你看看社区的解决方案,如果你需要与这些案件关注:

Just a word of advice as well... if you are trying to set up a PHP based git client, you are going to have to handle a ton of fail cases, one of which is readily apparent in this code... attempting a commit when no new files have been modified. I'd encourage you to look at community solutions if you need to be concerned with these cases:

<一个href=\"http://stackoverflow.com/questions/9284283/is-there-a-good-php-git-client-with-http-support\">Is有一个很好的PHP的git客户端的HTTP支持?

这篇关于执行git的在当前目录下的PHP文件提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆