X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/5d065586f4c16c0ec6510dba97b0d5facb859d75..8668d95b319138d94792f3476a7b9098f667c7b6:/src/phorkie/Forker.php diff --git a/src/phorkie/Forker.php b/src/phorkie/Forker.php index 3425a72..7473f16 100644 --- a/src/phorkie/Forker.php +++ b/src/phorkie/Forker.php @@ -7,16 +7,18 @@ class Forker { $new = $this->fork($repo->gitDir); \copy($repo->gitDir . '/description', $new->gitDir . '/description'); + $this->index($new); return $new; } - public function forkRemote($url) + public function forkRemote($cloneUrl, $originalUrl) { - $new = $this->fork($url); + $new = $this->fork($cloneUrl); file_put_contents( $new->gitDir . '/description', - 'Fork of ' . $url + 'Fork of ' . $originalUrl ); + $this->index($new); return $new; } @@ -26,19 +28,38 @@ class Forker $rs = new Repositories(); $new = $rs->createNew(); $vc = $new->getVc(); - \rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not - $vc->getCommand('clone') + + //VersionControl_Git wants an existing dir, git clone not + \rmdir($new->gitDir); + + $cmd = $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( + $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git' + ) ->addArgument($pathOrUrl) - ->addArgument($new->workDir) - ->execute(); + ->addArgument($new->workDir); + try { + $cmd->execute(); + } catch (\Exception $e) { + //clean up, we've got no workdir otherwise + $new->delete(); + throw $e; + } + foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) { \unlink($hookfile); } + return $new; } + + protected function index($repo) + { + $db = new Database(); + $db->getIndexer()->addRepo($repo); + } } ?>