使用PHP运行`git push origin master`命令

时间:2016-01-13 22:21:18

标签: php git terminal proc-open

我正在设计一个应用程序,它有一个git层,可以让我从Web浏览器执行提交,而不必去CLI。 git repo将在我自己的服务器上。 git进程的一部分是git push origin master,但它有一个密码提示。

执行代码

private function run($command, array $arguments = array()) {
    $pipes = array();
    $descriptorspec = array(
       array('pipe', 'r'),  // STDIN
       array('pipe', 'w'),  // STDOUT
       array('file', 'temp/error.txt', 'w'),  // STDERR
    );
    $process = proc_open($command, $descriptorspec, $pipes);
    foreach ($arguments as $arg) {
        // Write each of the supplied arguments to STDIN
        fwrite($pipes[0], (preg_match("/\n(:?\s+)?$/", $arg) ? $arg : "{$arg}\n"));
    }
    $response = stream_get_contents($pipes[1]);
    // Make sure that each pipe is closed to prevent a lockout
    foreach ($pipes as $pipe) {
        fclose($pipe);
    }
    proc_close($process);
    return $response;
}

我将使用

调用该函数
$git->run('git push origin master', array('username', 'password'));

完成上述操作绝对没有。

在上述代码的调试过程中,我运行了php -i并得到了一些返回的数据。然后我运行aasdashdlashdkashdl,即我知道的脚本不存在,但仍然没有返回任何错误输出。使用此函数运行git status将返回输出,而git add .不返回任何内容并且对git repo不执行任何操作。

我做错了什么?我可以使用证书吗(但是你有自签名证书的问题,我不仅可以在我的个人电脑上开发,还可以在其他电脑上开发)?

NB

我试图保持"香草"尽可能地,并且宁愿不必添加大量的包,但我愿意,如果没有其他解决方案。

0 个答案:

没有答案