read full name from Yahoo! OpenID
[phorkie.git] / www / fork.php
1 <?php
2 /**
3  * Fork a repository
4  */
5 namespace phorkie;
6 $reqWritePermissions = true;
7 require_once 'www-header.php';
8
9 if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
10     throw new Exception_Input('Forking only possible via POST');
11 }
12
13 $repo = new Repository();
14 $repo->loadFromRequest();
15
16 $rs = new Repositories();
17 $new = $rs->createNew();
18 $vc = $new->getVc();
19 \rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not
20 $vc->getCommand('clone')
21     //this should be setOption, but it fails with a = between name and value
22     ->addArgument('--separate-git-dir')
23     ->addArgument($GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git')
24     ->addArgument($repo->gitDir)
25     ->addArgument($new->workDir)
26     ->execute();
27 \copy($repo->gitDir . '/description', $new->gitDir . '/description');
28 foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
29     \unlink($hookfile);
30 }
31
32 //FIXME: where to put fork source link?
33 redirect($new->getLink('display'));
34 ?>