Handle command

The VersionControl_Git prepares OO interface of some Git feature, but it is not completely.

If you want to use full feature of Git by using VersionControl_Git, you should run Git command via VersionControl_Git_Util_Command.

To tell the truth, most of the feature of VersionControl_Git uses VersionControl_Git_Util_Command.

Now, I explain you how to use VersionControl_Git_Util_Command.

<?php

require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/home/co3k/sf/op3-ebihara');
$command $git->getCommand('show');

You can get an instance of VersionControl_Git_Util_Command by calling VersionControl_Git::getCommand() with sub-command name.

If you want to use options, add calling the setOption() method or the setOptions() method.

<?php

require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/home/co3k/sf/op3-ebihara');
$command $git->getCommand('show')
    ->
setOptions(array(
        
'pretty' => 'raw',
    ))
    ->
setOptions('pretty''raw');

The boolean option value is special. "true" is specified as option value, it doesn't have value. "false" is specified as option value, the option will not be used.

<?php

require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/home/co3k/sf/op3-ebihara');
$command $git->getCommand('show')
    ->
setOptions('oneline'true);

If you want to use arguments, add calling the addArgument() method or the setArguemnts() method.

<?php

require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/home/co3k/sf/op3-ebihara');
$command $git->getCommand('show')
    ->
setArguments(array('master''branch1'))
    ->
addArgument('branch2');

Ready to execute the command? Now you can call "execute()" method and get result.

<?php

require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/home/co3k/sf/op3-ebihara');
$result $git->getCommand('show')
    ->
setOption('oneline'true)
    ->
addArgument('master')
    ->
execute();
var_dump($result);

/*
result:

string(829) "9a259a5 changed url to JSON version of dashboard contents (fixes #509)
diff --git a/apps/pc_backend/modules/default/templates/topSuccess.php b/apps/pc_backend/modules/default/templates/topSuccess.php
index 3c7764e..cbfcf26 100644
  :
*/