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