<?php
+
namespace Cubist\Util\CommandLine;
use Cubist\Util\CommandLine;
-class Git extends CommandLine {
- protected $_repos;
+class Git extends CommandLine
+{
+ protected $_repos;
+
+ public function __construct($repos, $output = null, $error = true)
+ {
+ parent::__construct('git', $output, $error);
+ $this->_repos = $repos;
+ $this->cd($repos);
+ }
- public function __construct($repos, $output = null, $error = true) {
- parent::__construct('git', $output, $error);
- $this->_repos = $repos;
- $this->cd($repos);
- }
+ public function executeCmd($cmd)
+ {
+ $this->setManualArg($cmd);
+ $this->execute();
+ return $this->getOutput();
+ }
- public function executeCmd($cmd) {
- $this->setManualArg($cmd);
- $this->execute();
- return $cmd . ' :: ' . file_get_contents($this->output);
- }
-}
\ No newline at end of file
+ public function listBranches()
+ {
+ $b = $this->executeCmd('branch -r');
+ $bb = explode("\n", $b);
+ $branches = array();
+ foreach ($bb as $item) {
+ $item = trim($item);
+ if ($item == '') {
+ continue;
+ }
+ $e = explode('->', $item);
+ if (count($e) == 2) {
+ $item = $e[1];
+ } else {
+ $item = $e[0];
+ }
+ $e = explode("/", $item);
+ $branches[trim($e[1])] = true;
+ }
+ return array_keys($branches);
+ }
+}