1. Go to this page and download the library: Download sweetchuck/robo-git library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sweetchuck / robo-git example snippets
declare(strict_types = 1);
class RoboFileExample extends \Robo\Tasks
{
use \Sweetchuck\Robo\Git\GitTaskLoader;
public function gitBranches(string $dir = '.')
{
return $this
->collectionBuilder()
->addTask(
$this
->taskGitBranchList()
->setWorkingDirectory($dir)
// Available options:
// --all
// --color
// --contains
// --format
// --list
// --merged
// --points-at
// --sort
)
->addCode(function (\Robo\State\Data $data): int {
// Here you can do whatever you want with the branches.
$output = $this->output();
foreach ($data['gitBranches'] as $longName => $branch) {
$output->writeln($longName);
foreach ($branch as $key => $value) {
$output->writeln(" $key = " . var_export($value, true));
}
}
return 0;
});
}
}
declare(strict_types = 1);
class RoboFileExample extends \Robo\Tasks
{
use \Sweetchuck\Robo\Git\GitTaskLoader;
/**
* @command git:config:get
*/
public function gitConfigGet(string $name)
{
return $this
->collectionBuilder()
->addTask(
$this
->taskGitConfigGet()
->setName($name)
)
->addCode(function (\Robo\State\Data $data) use ($name): int {
$key = "git.config.$name";
$this->output()->writeln("$key = {$data[$key]}");
return 0;
});
}
}
declare(strict_types = 1);
class RoboFileExample extends \Robo\Tasks
{
use \Sweetchuck\Robo\Git\GitTaskLoader;
/**
* @command git:current-branch
*/
public function gitCurrentBranch()
{
return $this
->collectionBuilder()
->addTask($this->taskGitCurrentBranch())
->addCode(function (\Robo\State\Data $data): int {
$this->output()->writeln("long = {$data['gitCurrentBranch.long']}");
$this->output()->writeln("short = {$data['gitCurrentBranch.short']}");
return 0;
});
}
}