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