first work on Fork origin display; works for local forks
[phorkie.git] / src / phorkie / Repository / ConnectionInfo.php
diff --git a/src/phorkie/Repository/ConnectionInfo.php b/src/phorkie/Repository/ConnectionInfo.php
new file mode 100644 (file)
index 0000000..3815856
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace phorkie;
+
+class Repository_ConnectionInfo
+{
+    protected $arConfig;
+    protected $repo;
+
+
+    public function __construct(Repository $repo)
+    {
+        $this->repo = $repo;
+        $this->arConfig = parse_ini_file($this->repo->gitDir . '/config', true);
+    }
+
+    public function isFork()
+    {
+        return $this->getOrigin() !== null;
+    }
+
+
+    public function getOrigin()
+    {
+        return $this->getRemote('origin');
+    }
+
+    /**
+     * @return Repository_Remote|null NULL if the remote does not exist, array
+     *                                with repository information otherwise
+     */
+    public function getRemote($name)
+    {
+        if (!isset($this->arConfig['remote ' . $name])) {
+            return null;
+        }
+        return new Repository_Remote($name, $this->arConfig['remote ' . $name]);
+    }
+
+}
+
+
+?>