X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/003e7c8a933084aa7873076e974bd39e92c142b8..43b23197ffc3e1d08a1e08b09dbb31f06692d7ff:/src/phorkie/Forker.php diff --git a/src/phorkie/Forker.php b/src/phorkie/Forker.php index affa12a..b4ab449 100644 --- a/src/phorkie/Forker.php +++ b/src/phorkie/Forker.php @@ -6,17 +6,49 @@ class Forker public function forkLocal($repo) { $new = $this->fork($repo->gitDir); + \copy($repo->gitDir . '/description', $new->gitDir . '/description'); + $new->getVc() + ->getCommand('config') + ->addArgument('remote.origin.title') + ->addArgument(file_get_contents($repo->gitDir . '/description')) + ->execute(); + + $this->index($new); + + $not = new Notificator(); + $not->create($new); + return $new; } - public function forkRemote($cloneUrl, $originalUrl) + public function forkRemote($cloneUrl, $originalUrl, $title = null) { $new = $this->fork($cloneUrl); - file_put_contents( - $new->gitDir . '/description', - 'Fork of ' . $originalUrl - ); + + $new->getVc() + ->getCommand('config') + ->addArgument('remote.origin.title') + ->addArgument($title) + ->execute(); + if ($originalUrl != $cloneUrl) { + $new->getVc() + ->getCommand('config') + ->addArgument('remote.origin.homepage') + ->addArgument($originalUrl) + ->execute(); + } + + if ($title === null) { + $title = 'Fork of ' . $originalUrl; + } + file_put_contents($new->gitDir . '/description', $title); + + $this->index($new); + + $not = new Notificator(); + $not->create($new); + return $new; } @@ -26,23 +58,37 @@ 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(); - foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) { - \unlink($hookfile); + ->addArgument($new->workDir); + try { + $cmd->execute(); + } catch (\Exception $e) { + //clean up, we've got no workdir otherwise + $new->delete(); + throw $e; } - $db = new Database(); - $db->getIndexer()->addRepo($new); + $rs = new Repository_Setup($new); + $rs->afterInit(); return $new; } + + protected function index($repo) + { + $db = new Database(); + $db->getIndexer()->addRepo($repo); + } } ?>