hide additional fields and add button to show them
[phorkie.git] / www / fork.php
index 6bec5f03bd0cba3f5cf76ee0416a666519fa2761..799763273667ec8388b1f94e70ab3688c9af60f9 100644 (file)
@@ -2,20 +2,30 @@
 /**
  * Fork a repository
  */
-namespace Phorkie;
+namespace phorkie;
 require_once 'www-header.php';
+
+if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
+    throw new Exception_Input('Forking only possible via POST');
+}
+
 $repo = new Repository();
 $repo->loadFromRequest();
 
 $rs = new Repositories();
 $new = $rs->createNew();
-$new->getVc()->getCommand('clone')
-    ->addArgument($repo->repoDir)
-    ->addArgument($new->repoDir)
+$vc = $new->getVc();
+\rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not
+$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($repo->gitDir)
+    ->addArgument($new->workDir)
     ->execute();
-\copy($repo->repoDir . '/.git/description', $new->repoDir . '/.git/description');
-foreach (glob($new->repoDir . '/.git/hooks/*') as $hookfile) {
-    unlink($hookfile);
+\copy($repo->gitDir . '/description', $new->gitDir . '/description');
+foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
+    \unlink($hookfile);
 }
 
 //FIXME: where to put fork source link?