separate git and work directories - gives nicer public git clone urls
[phorkie.git] / www / fork.php
index 50049454606049b6b12c27cc6c037aae7e797ee4..799763273667ec8388b1f94e70ab3688c9af60f9 100644 (file)
@@ -2,18 +2,32 @@
 /**
  * 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');
+\copy($repo->gitDir . '/description', $new->gitDir . '/description');
+foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
+    \unlink($hookfile);
+}
+
 //FIXME: where to put fork source link?
 redirect($new->getLink('display'));
 ?>
\ No newline at end of file