Move 'no-fork-url' error message to top of page
[phorkie.git] / src / phorkie / Forker.php
index affa12ae47df853809968ce73f7d502158d3bb0d..157cb5e3e435a6a78da4bb087469fb3de9fa2f2f 100644 (file)
@@ -7,6 +7,7 @@ class Forker
     {
         $new = $this->fork($repo->gitDir);
         \copy($repo->gitDir . '/description', $new->gitDir . '/description');
+        $this->index($new);
         return $new;
     }
 
@@ -17,6 +18,7 @@ class Forker
             $new->gitDir . '/description',
             'Fork of ' . $originalUrl
         );
+        $this->index($new);
         return $new;
     }
 
@@ -26,23 +28,37 @@ class Forker
         $rs = new Repositories();
         $new = $rs->createNew();
         $vc = $new->getVc();
-        \rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not
-        $vc->getCommand('clone')
+
+        //VersionControl_Git wants an existing dir, git clone not
+        \rmdir($new->gitDir);
+
+        $cmd = $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);
+            ->addArgument($new->workDir);
+        try {
+            $cmd->execute();
+        } catch (\Exception $e) {
+            //clean up, we've got no workdir otherwise
+            $new->delete();
+            throw $e;
         }
 
-        $db = new Database();
-        $db->getIndexer()->addRepo($new);
+        $rs = new Repository_Setup($new);
+        $rs->afterInit();
 
         return $new;
     }
+
+    protected function index($repo)
+    {
+        $db = new Database();
+        $db->getIndexer()->addRepo($repo);
+    }
 }
 
 ?>