summaryrefslogtreecommitdiff
path: root/www/fork.php
blob: 799763273667ec8388b1f94e70ab3688c9af60f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
 * Fork a repository
 */
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();
$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->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'));
?>