]> _ Git - cubist_util.git/commitdiff
wip #5400 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 16:08:01 +0000 (18:08 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 16:08:01 +0000 (18:08 +0200)
src/CommandLine/Git.php

index cbf2b492cb55d648060b1e9444a6c971c9e0ec0e..9eb3f9c61626599286f29d8750bdd2ff1c99cd52 100644 (file)
@@ -1,20 +1,46 @@
 <?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);
+    }
+}