do not try to delete if file does not exist
[phorkie.git] / src / phorkie / Forker.php
index 3425a72283eefaa2f758301be6863bc8e155a178..f293455a54010187c2c8b667f23d17c204aa5106 100644 (file)
@@ -7,16 +7,18 @@ class Forker
     {
         $new = $this->fork($repo->gitDir);
         \copy($repo->gitDir . '/description', $new->gitDir . '/description');
+        $this->index($new);
         return $new;
     }
 
-    public function forkRemote($url)
+    public function forkRemote($cloneUrl, $originalUrl)
     {
-        $new = $this->fork($url);
+        $new = $this->fork($cloneUrl);
         file_put_contents(
             $new->gitDir . '/description',
-            'Fork of ' . $url
+            'Fork of ' . $originalUrl
         );
+        $this->index($new);
         return $new;
     }
 
@@ -26,19 +28,31 @@ class Forker
         $rs = new Repositories();
         $new = $rs->createNew();
         $vc = $new->getVc();
-        \rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not
+
+        //VersionControl_Git wants an existing dir, git clone not
+        \rmdir($new->gitDir);
+
         $vc->getCommand('clone')
             //this should be setOption, but it fails with a = between name and value
             ->addArgument('--separate-git-dir')
-            ->addArgument($GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git')
+            ->addArgument(
+                $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git'
+            )
             ->addArgument($pathOrUrl)
             ->addArgument($new->workDir)
             ->execute();
         foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
             \unlink($hookfile);
         }
+
         return $new;
     }
+
+    protected function index($repo)
+    {
+        $db = new Database();
+        $db->getIndexer()->addRepo($repo);
+    }
 }
 
 ?>