在浏览器中通过php运行git命令

时间:2014-05-07 10:53:54

标签: php git browser

编辑:我设法通过proc_open()打印出stderr然后使用那里的信息进行调试来实现这一点。

这是我的第一个问题,所以如果格式不正确,我会道歉。

我正在尝试通过浏览器中的php运行以下命令:

git init
git add *
git commit -a -m "commit message 01"

页面的网址是     本地主机/ jbrowse / testingphp / phpInsteadOfPerl.php

我在我的脚本中尝试了以下内容: passthru(),shell_exec(),exec(),system()

############using passthru############
passthru('git init');
passthru('git add *');
passthru('git commit -a -m "commit message 01"');

将此打印到浏览器: 在/Library/WebServer/Documents/jbrowse/testingphp/.git /

中重新初始化现有的Git存储库
############using shell_exec()############
$one = shell_exec('git init');
$two = shell_exec('git add *');
$three = shell_exec('git commit -a -m "commit message 01"');
echo "$one";
echo "$two";
echo "$three";

将此打印到浏览器: 在/Library/WebServer/Documents/jbrowse/testingphp/.git /

中重新初始化现有的Git存储库
############using exec()############
$one = exec('git init', $oneOutput, $oneReturn);
$two = exec('git add *', $twoOutput, $twoReturn);
$three = exec('git commit -a -m "commit message 01"', $threeOutput, $threeReturn);
echo "one: $one";
echo "two: $two";
echo "three: $three";
echo "<br>";

echo "oneOutput: ";
echo join($oneOutput);

echo "twoOutput: ";
echo join($twoOutput);

echo "threeOutput: ";
echo join($threeOutput);
echo "<br>";

echo "oneReturn: $oneReturn ";
echo "twoReturn: $twoReturn ";
echo "threeReturn: $threeReturn ";

给出: 一:在/Library/WebServer/Documents/jbrowse/testingphp/.git/two中重新初始化现有的Git存储库:三:

oneOutput:在/Library/WebServer/Documents/jbrowse/testingphp/.git/twoOutput中重新初始化现有的Git存储库:threeOutput:

oneReturn:0 twoReturn:0 threeReturn:128

128,根据以下链接,表示“退出的参数无效”http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/exitcodes.html

############using system()############
system('git init');
system('git add *');
system('git commit -a -m "commit message 01"');

给出: 在/Library/WebServer/Documents/jbrowse/testingphp/.git /

中重新初始化现有的Git存储库

如果我从终端运行这些php脚本,所有git命令都可以完美执行。

我认为这可能是一个权限问题,因此我已经为所有用户提供了对/ testingphp和/.git文件夹中所有内容的完全权限。 (当然.git文件夹的权限在重新初始化时会恢复为默认值,但是如果我取出代码的git init部分,那么它仍然无效。)

所有文件和目录的权限如下: (test001.sh是一个shell脚本,我将git命令放入其中并尝试通过php调用它。)

la-mckiernan:testingphp robertmckiernan$ ls -al
total 24
drwxrwxrwx   5 robertmckiernan  wheel   170  6 May 14:45 .
drwxr-xrwx  24 robertmckiernan  wheel   816  6 May 13:27 ..
drwxrwxrwx  13 robertmckiernan  wheel   442  7 May 10:28 .git
-rwxrwxrwx@  1 robertmckiernan  wheel  2628  7 May 10:28 phpInsteadOfPerl.php
-rwxrwxrwx   1 robertmckiernan  wheel    75  6 May 15:25 test001.sh

la-mckiernan:.git robertmckiernan$ ls -al
total 40
drwxrwxrwx  13 robertmckiernan  wheel   442  7 May 10:28 .
drwxrwxrwx   5 robertmckiernan  wheel   170  6 May 14:45 ..
-rwxrwxrwx   1 robertmckiernan  wheel     6  6 May 16:50 COMMIT_EDITMSG
-rwxrwxrwx   1 robertmckiernan  wheel    23  6 May 14:45 HEAD
drwxrwxrwx   2 _www             wheel    68  6 May 16:34 branches
-rwxrwxrwx   1 _www             wheel   137  7 May 10:28 config
-rwxrwxrwx   1 robertmckiernan  wheel    73  6 May 14:45 description
drwxrwxrwx  11 robertmckiernan  wheel   374  6 May 14:45 hooks
-rwxrwxrwx   1 _www             wheel   214  7 May 10:28 index
drwxrwxrwx   3 robertmckiernan  wheel   102  6 May 14:45 info
drwxrwxrwx   4 robertmckiernan  wheel   136  6 May 14:45 logs
drwxrwxrwx  44 robertmckiernan  wheel  1496  7 May 10:27 objects
drwxrwxrwx   4 robertmckiernan  wheel   136  6 May 14:45 refs

我正在使用mac OSX mavericks。

0 个答案:

没有答案