From 188cc56aa7074b26311319818af12917cdcc468c Mon Sep 17 00:00:00 2001 From: Rich Sage Date: Wed, 20 Apr 2011 23:58:33 +0100 Subject: [PATCH 1/2] Added support for repositories accessible via SSH. --- README.rst | 3 ++ src/Sismo/GithubProject.php | 2 +- src/Sismo/HTTPProject.php | 41 +++++++++++++++++++++++++++ src/Sismo/Project.php | 5 ---- tests/Sismo/Tests/HTTPProjectTest.php | 25 ++++++++++++++++ tests/Sismo/Tests/ProjectTest.php | 8 +++--- 6 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 src/Sismo/HTTPProject.php create mode 100644 tests/Sismo/Tests/HTTPProjectTest.php diff --git a/README.rst b/README.rst index 3f5d4b0..0fc54b9 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,9 @@ By default, Sismo reads its configuration from ``~/.sismo/config.php``:: // add a remote Github repository $projects[] = new Sismo\GithubProject('Twig', 'fabpot/Twig', $notifier); + // add a repository accessible via SSH + $projects[] = new Sismo\Project('Twig' 'git@github.com:fabpot/Twig.git'); + // add a project with custom settings $sf2 = new Sismo\Project('Symfony'); $sf2->setRepository('https://github.com/symfony/symfony.git'); diff --git a/src/Sismo/GithubProject.php b/src/Sismo/GithubProject.php index ad363f9..ecda6f8 100644 --- a/src/Sismo/GithubProject.php +++ b/src/Sismo/GithubProject.php @@ -18,7 +18,7 @@ * * @author Fabien Potencier */ -class GithubProject extends Project +class GithubProject extends HTTPProject { public function setRepository($url) { diff --git a/src/Sismo/HTTPProject.php b/src/Sismo/HTTPProject.php new file mode 100644 index 0000000..5edb544 --- /dev/null +++ b/src/Sismo/HTTPProject.php @@ -0,0 +1,41 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sismo; + +use Symfony\Component\Process\Process; + +/** + * Describes a project which uses Git URLs in the form + * of https://example.com/username/MyProject.git@mybranch + * + * @author Fabien Potencier + * @author Rich Sage + */ +class HTTPProject extends Project +{ + /** + * Sets the repository URL after splitting to + * find the branch (where present) + * + * @param $url + * @return void + */ + public function setRepository($url) + { + if (false !== strpos($url, '@')) { + list($url, $branch) = explode('@', $url); + $this->setBranch($branch); + } + + parent::setRepository($url); + } +} diff --git a/src/Sismo/Project.php b/src/Sismo/Project.php index f131e89..b2adc43 100644 --- a/src/Sismo/Project.php +++ b/src/Sismo/Project.php @@ -158,11 +158,6 @@ public function getRepository() public function setRepository($url) { - if (false !== strpos($url, '@')) { - list($url, $branch) = explode('@', $url); - $this->branch = $branch; - } - $this->repository = $url; } diff --git a/tests/Sismo/Tests/HTTPProjectTest.php b/tests/Sismo/Tests/HTTPProjectTest.php new file mode 100644 index 0000000..91735d9 --- /dev/null +++ b/tests/Sismo/Tests/HTTPProjectTest.php @@ -0,0 +1,25 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Sismo\Tests; + +use Sismo\HTTPProject; + +class HTTPProjectTest extends \PHPUnit_Framework_TestCase +{ + public function testSetRepository() + { + $project = new HTTPProject('Twig Local'); + $project->setRepository('https://github.com/fabpot/Twig.git@feat'); + $this->assertEquals('https://github.com/fabpot/Twig.git', $project->getRepository()); + $this->assertEquals('feat', $project->getBranch()); + } +} diff --git a/tests/Sismo/Tests/ProjectTest.php b/tests/Sismo/Tests/ProjectTest.php index cb2160a..76e6841 100644 --- a/tests/Sismo/Tests/ProjectTest.php +++ b/tests/Sismo/Tests/ProjectTest.php @@ -32,8 +32,8 @@ public function testConstructor() $this->assertEquals('master', $project->getBranch()); $project = new Project('Twig Local', 'repo@feat'); - $this->assertEquals('repo', $project->getRepository()); - $this->assertEquals('feat', $project->getBranch()); + $this->assertEquals('repo@feat', $project->getRepository()); + $this->assertEquals('master', $project->getBranch()); $project = new Project('Twig Local', 'repo', array( $notifier1 = $this->getMock('Sismo\Notifier'), @@ -170,8 +170,8 @@ public function testRepository() $this->assertEquals('https://github.com/fabpot/Twig.git', $project->getRepository()); $project->setRepository('https://github.com/fabpot/Twig.git@feat'); - $this->assertEquals('https://github.com/fabpot/Twig.git', $project->getRepository()); - $this->assertEquals('feat', $project->getBranch()); + $this->assertEquals('https://github.com/fabpot/Twig.git@feat', $project->getRepository()); + $this->assertEquals('master', $project->getBranch()); } public function testCommand() From 240b87387bbb6f394ad19a0adf90d2d6ccac77e3 Mon Sep 17 00:00:00 2001 From: Rich Sage Date: Thu, 21 Apr 2011 21:35:40 +0100 Subject: [PATCH 2/2] Added HTTPProject into the compile script. --- compile | 1 + 1 file changed, 1 insertion(+) diff --git a/compile b/compile index fbc4b27..c5f02a2 100755 --- a/compile +++ b/compile @@ -110,6 +110,7 @@ $classes = array( 'Sismo\Storage', 'Sismo\Builder', 'Sismo\Project', + 'Sismo\HTTPProject', 'Sismo\GithubProject', 'Sismo\Notifier', 'Sismo\GrowlNotifier',