From 8701af280fa5a9c83827cdd0e2ae335d2512a3a7 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 19 Sep 2012 23:52:07 +0200 Subject: [PATCH] move forking code to separate class --- src/phorkie/Forker.php | 44 ++++++++++++++++++++++++++++++++++++++++++ www/fork.php | 17 ++-------------- 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/phorkie/Forker.php diff --git a/src/phorkie/Forker.php b/src/phorkie/Forker.php new file mode 100644 index 0000000..3425a72 --- /dev/null +++ b/src/phorkie/Forker.php @@ -0,0 +1,44 @@ +fork($repo->gitDir); + \copy($repo->gitDir . '/description', $new->gitDir . '/description'); + return $new; + } + + public function forkRemote($url) + { + $new = $this->fork($url); + file_put_contents( + $new->gitDir . '/description', + 'Fork of ' . $url + ); + return $new; + } + + + protected function fork($pathOrUrl) + { + $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($pathOrUrl) + ->addArgument($new->workDir) + ->execute(); + foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) { + \unlink($hookfile); + } + return $new; + } +} + +?> diff --git a/www/fork.php b/www/fork.php index 6c96a6a..d8a24a2 100644 --- a/www/fork.php +++ b/www/fork.php @@ -13,21 +13,8 @@ if ($_SERVER['REQUEST_METHOD'] !== '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); -} +$forker = new Forker(); +$new = $forker->forkLocal($repo); //FIXME: where to put fork source link? redirect($new->getLink('display')); -- 2.30.2