From ffe27b2a757597807a2870cc47e93c791159ba06 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:06:03 +0100 Subject: [PATCH 01/14] Add routing service to handle repos in subdirectories --- src/GitList/Application.php | 2 + .../Provider/RoutingUtilServiceProvider.php | 26 ++++++++++ src/GitList/Util/Routing.php | 51 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/GitList/Provider/RoutingUtilServiceProvider.php create mode 100644 src/GitList/Util/Routing.php diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 739f0a2..7f7e2cd 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -8,6 +8,7 @@ use Silex\Provider\UrlGeneratorServiceProvider; use GitList\Provider\GitServiceProvider; use GitList\Provider\RepositoryUtilServiceProvider; use GitList\Provider\ViewUtilServiceProvider; +use GitList\Provider\RoutingUtilServiceProvider; /** * GitList application. @@ -44,6 +45,7 @@ class Application extends SilexApplication $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); + $this->register(new RoutingUtilServiceProvider()); $this['twig'] = $this->share($this->extend('twig', function($twig, $app) { $twig->addFilter('md5', new \Twig_Filter_Function('md5')); diff --git a/src/GitList/Provider/RoutingUtilServiceProvider.php b/src/GitList/Provider/RoutingUtilServiceProvider.php new file mode 100644 index 0000000..95b43d6 --- /dev/null +++ b/src/GitList/Provider/RoutingUtilServiceProvider.php @@ -0,0 +1,26 @@ +share(function () use ($app) { + return new Routing($app); + }); + } + + public function boot(Application $app) + { + } +} diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php new file mode 100644 index 0000000..c82438a --- /dev/null +++ b/src/GitList/Util/Routing.php @@ -0,0 +1,51 @@ +app = $app; + } + + public function getRepositoryRegex() + { + static $regex = null; + + if ($regex === null) { + $app = $this->app; + $quoted_paths = array_map( + function ($repo) use ($app) { + return preg_quote($app['util.routing']->getRelativePath($repo['path']), '/'); + }, + $this->app['git']->getRepositories($this->app['git.repos']) + ); + $regex = '/' . implode('|', $quoted_paths) . '/'; + } + + return $regex; + } + + /** + * Strips the base path from a full repository path + * + * @param string $repo_path Full path to the repository + * @return string Relative path to the repository from git.repositories + */ + public function getRelativePath($repo_path) + { + if (strpos($repo_path, $this->app['git.repos']) === 0) { + $relative_path = substr($repo_path, strlen($this->app['git.repos'])); + return ltrim($relative_path, '/'); + } else { + throw new \InvalidArgumentException( + sprintf("Path '%s' does not match configured repository directory", $repo_path) + ); + } + } +} From 57b96f448f5ed05da6fb3fd5c75c153f77c4dd30 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:16:58 +0100 Subject: [PATCH 02/14] Change delimiter for repository regex '#' is the default delimiter for route regexes in `Symfony\Component\Routing\RouteCompiler`, so use this. --- src/GitList/Util/Routing.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index c82438a..0ad87e8 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -21,7 +21,7 @@ class Routing $app = $this->app; $quoted_paths = array_map( function ($repo) use ($app) { - return preg_quote($app['util.routing']->getRelativePath($repo['path']), '/'); + return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); }, $this->app['git']->getRepositories($this->app['git.repos']) ); From f3fa152eccbf8333d053281104baad52dcabd369 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:20:23 +0100 Subject: [PATCH 03/14] Remove delimiters from repository regex --- src/GitList/Util/Routing.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index 0ad87e8..c283fec 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -25,7 +25,7 @@ class Routing }, $this->app['git']->getRepositories($this->app['git.repos']) ); - $regex = '/' . implode('|', $quoted_paths) . '/'; + $regex = implode('|', $quoted_paths); } return $regex; From 3c9205a079f036e00191853f59ea3d18343ab281 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:44:45 +0100 Subject: [PATCH 04/14] Sort repository regex paths by longest first --- src/GitList/Util/Routing.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index c283fec..0f22dae 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -25,6 +25,7 @@ class Routing }, $this->app['git']->getRepositories($this->app['git.repos']) ); + usort($quoted_paths, function ($a, $b) { return strlen($b) - strlen($a); }); $regex = implode('|', $quoted_paths); } From 668cd97ebe2071b264e56af470a16b8fdf6e8c8b Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:46:19 +0100 Subject: [PATCH 05/14] Use computed regex for repo --- src/GitList/Controller/BlobController.php | 4 ++-- src/GitList/Controller/CommitController.php | 8 ++++---- src/GitList/Controller/MainController.php | 4 ++-- src/GitList/Controller/TreeController.php | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/GitList/Controller/BlobController.php b/src/GitList/Controller/BlobController.php index 82fc2a4..9a44a27 100644 --- a/src/GitList/Controller/BlobController.php +++ b/src/GitList/Controller/BlobController.php @@ -39,7 +39,7 @@ class BlobController implements ControllerProviderInterface 'tags' => $repository->getTags(), )); })->assert('file', '.+') - ->assert('repo', '[\w-._]+') + ->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('blob'); @@ -59,7 +59,7 @@ class BlobController implements ControllerProviderInterface return new Response($blob, 200, $headers); })->assert('file', '.+') - ->assert('repo', '[\w-._]+') + ->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('blob_raw'); diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index f47b0a5..776f669 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -38,7 +38,7 @@ class CommitController implements ControllerProviderInterface 'commits' => $categorized, 'file' => $file, )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->assert('file', '.+') ->value('branch', 'master') @@ -63,7 +63,7 @@ class CommitController implements ControllerProviderInterface 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->bind('searchcommits'); $route->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) { @@ -75,7 +75,7 @@ class CommitController implements ControllerProviderInterface 'repo' => $repo, 'commit' => $commit, )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('commit', '[a-f0-9^]+') ->bind('commit'); @@ -94,7 +94,7 @@ class CommitController implements ControllerProviderInterface 'tags' => $repository->getTags(), 'blames' => $blames, )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('file', '.+') ->assert('branch', '[\w-._\/]+') ->bind('blame'); diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index dcf17cc..ed187c7 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -33,7 +33,7 @@ class MainController implements ControllerProviderInterface 'stats' => $stats, 'authors' => $authors, )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->value('branch', 'master') ->bind('stats'); @@ -49,7 +49,7 @@ class MainController implements ControllerProviderInterface )); return new Response($html, 200, array('Content-Type' => 'application/rss+xml')); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('rss'); diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index f7cd7eb..fe463b7 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -41,7 +41,7 @@ class TreeController implements ControllerProviderInterface 'tags' => $repository->getTags(), 'readme' => $app['util.repository']->getReadme($repo, $branch), )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->assert('tree', '.+') ->bind('tree'); @@ -65,19 +65,19 @@ class TreeController implements ControllerProviderInterface 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), )); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('search'); $route->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) { return $treeController($repo, $branch); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('branch'); $route->get('{repo}/', function($repo) use ($app, $treeController) { return $treeController($repo); - })->assert('repo', '[\w-._]+') + })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->bind('repository'); $route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) { @@ -108,7 +108,7 @@ class TreeController implements ControllerProviderInterface 'Content-Transfer-Encoding' => 'binary', )); })->assert('format', '(zip|tar)') - ->assert('repo', '[\w-._]+') + ->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->bind('archive'); From ef014943180431df5826b9fd5f4ad12c75839809 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:52:45 +0100 Subject: [PATCH 06/14] Use relative paths for repositories --- src/GitList/Controller/MainController.php | 8 +++++++- views/index.twig | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index ed187c7..a223721 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -13,7 +13,13 @@ class MainController implements ControllerProviderInterface $route = $app['controllers_factory']; $route->get('/', function() use ($app) { - $repositories = $app['git']->getRepositories($app['git.repos']); + $repositories = array_map( + function ($repo) use ($app) { + $repo['relative_path'] = $app['util.routing']->getRelativePath($repo['path']); + return $repo; + }, + $app['git']->getRepositories($app['git.repos']) + ); return $app['twig']->render('index.twig', array( 'repositories' => $repositories, diff --git a/views/index.twig b/views/index.twig index db725ac..898fd20 100644 --- a/views/index.twig +++ b/views/index.twig @@ -9,8 +9,8 @@ {% for repository in repositories %}

{{ repository.description }}

From 32efd89781dad95d62c5c8977c908f064f22c586 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 14:59:32 +0100 Subject: [PATCH 07/14] Update composer to use dev-master of Gitter --- composer.json | 2 +- composer.lock | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index a62f8d9..49508ff 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "twig/twig": "1.9.*", "symfony/twig-bridge": "2.1.*", "symfony/filesystem": "2.1.*", - "klaussilveira/gitter": "0.1.2" + "klaussilveira/gitter": "dev-master" }, "require-dev": { "symfony/browser-kit": "2.1.*", diff --git a/composer.lock b/composer.lock index 7e3f6b3..786811c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,18 +1,18 @@ { - "hash": "c5848b4657d12dc6db9a2f2ff1dd9069", + "hash": "b1fc3d7e61707618f68e5cf940e97081", "packages": [ { "name": "klaussilveira/gitter", - "version": "0.1.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/klaussilveira/gitter", - "reference": "0.1.2" + "reference": "1c9b6e4dde81d21acffe99d9f4559ed3bc59f947" }, "dist": { "type": "zip", - "url": "https://github.com/klaussilveira/gitter/zipball/0.1.2", - "reference": "0.1.2", + "url": "https://github.com/klaussilveira/gitter/zipball/1c9b6e4dde81d21acffe99d9f4559ed3bc59f947", + "reference": "1c9b6e4dde81d21acffe99d9f4559ed3bc59f947", "shasum": "" }, "require": { @@ -22,9 +22,9 @@ "require-dev": { "symfony/filesystem": ">=2.1" }, - "time": "2012-10-30 17:34:56", + "time": "1351643953", "type": "library", - "installation-source": "dist", + "installation-source": "source", "autoload": { "psr-0": { "Gitter": "lib/" @@ -65,7 +65,6 @@ "require": { "php": ">=5.3.0" }, - "time": "1347278988", "type": "library", "extra": { "branch-alias": { @@ -92,7 +91,8 @@ "keywords": [ "dependency injection", "container" - ] + ], + "time": "1347278988" }, { "name": "silex/silex", @@ -245,7 +245,6 @@ "require": { "php": ">=5.3.3" }, - "time": "1350717030", "type": "library", "extra": { "branch-alias": { @@ -272,7 +271,8 @@ } ], "description": "Symfony Filesystem Component", - "homepage": "http://symfony.com" + "homepage": "http://symfony.com", + "time": "1350717030" }, { "name": "symfony/http-foundation", @@ -409,7 +409,6 @@ "require": { "php": ">=5.3.3" }, - "time": "1351356874", "type": "library", "extra": { "branch-alias": { @@ -436,7 +435,8 @@ } ], "description": "Symfony Process Component", - "homepage": "http://symfony.com" + "homepage": "http://symfony.com", + "time": "1351356874" }, { "name": "symfony/routing", @@ -531,7 +531,6 @@ "symfony/yaml": "2.1.*", "symfony/security": "2.1.*" }, - "time": "1349363877", "type": "symfony-bridge", "extra": { "branch-alias": { @@ -558,7 +557,8 @@ } ], "description": "Symfony Twig Bridge", - "homepage": "http://symfony.com" + "homepage": "http://symfony.com", + "time": "1349363877" }, { "name": "twig/twig", @@ -615,7 +615,7 @@ ], "minimum-stability": "dev", - "stability-flags": [ - - ] + "stability-flags": { + "klaussilveira/gitter": 20 + } } From 87d6391ba4f65ed07fdb778abdac52b9d0ff451b Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 18:03:42 +0100 Subject: [PATCH 08/14] Add `fromFile` factory method to `GitList\Config` --- boot.php | 2 +- src/GitList/Config.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/boot.php b/boot.php index 3a5b62b..d5aa475 100644 --- a/boot.php +++ b/boot.php @@ -1,7 +1,7 @@ set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); // Startup and configure Silex application diff --git a/src/GitList/Config.php b/src/GitList/Config.php index a7f09e3..33d5b39 100644 --- a/src/GitList/Config.php +++ b/src/GitList/Config.php @@ -6,13 +6,17 @@ class Config { protected $data; - public function __construct($file) - { + public static function fromFile($file) { if (!file_exists($file)) { die(sprintf('Please, create the %1$s file.', $file)); } + $data = parse_ini_file($file, true); + return new static($data); + } - $this->data = parse_ini_file($file, true); + public function __construct($data) + { + $this->data = $data; $this->validateOptions(); } From d46704d21e0b5a694e7682724b04a945aefa53bc Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 18:06:30 +0100 Subject: [PATCH 09/14] Moved config loading to index.php As `index.php` is the entry point of the webapp, loading configuration data from the `config.ini` should take place there. This makes testing easier, since a properly formatted `config.ini` (whose values are overriden anyway) is no longer needed. --- index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index bed5d93..51eaaa6 100644 --- a/index.php +++ b/index.php @@ -11,5 +11,9 @@ if (!ini_get('date.timezone')) { } require 'vendor/autoload.php'; + +// Load configuration +$config = GitList\Config::fromFile('config.ini'); + $app = require 'boot.php'; -$app->run(); \ No newline at end of file +$app->run(); From 3400c29a0dd8576b96e344e5eb857e650ccee2e2 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 18:14:20 +0100 Subject: [PATCH 10/14] Die when no config object provided Just a friendlier error message, when `boot.php` is included without a global `$config` object being set. --- boot.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index d5aa475..5e36efe 100644 --- a/boot.php +++ b/boot.php @@ -1,7 +1,9 @@ set('git', 'repositories', rtrim($config->get('git', 'repositories'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); // Startup and configure Silex application From 655ee6b85a49a9dd37701f82798ddf3eb3d246b7 Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 18:21:52 +0100 Subject: [PATCH 11/14] Make unit tests use new configuration constructor --- tests/InterfaceTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 95c8b86..d56f6b2 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -7,6 +7,7 @@ use Gitter\Client; class InterfaceTest extends WebTestCase { protected static $tmpdir; + protected static $git_path; public static function setUpBeforeClass() { @@ -31,6 +32,8 @@ class InterfaceTest extends WebTestCase $options['hidden'] = array(self::$tmpdir . '/hiddenrepo'); $git = new Client($options); + self::$git_path = $options['path']; + // GitTest repository fixture $git->createRepository(self::$tmpdir . 'GitTest'); $repository = $git->getRepository(self::$tmpdir . 'GitTest'); @@ -61,9 +64,16 @@ class InterfaceTest extends WebTestCase public function createApplication() { + $config = new \GitList\Config(array( + 'git' => array( + 'client' => self::$git_path, + 'repositories' => self::$tmpdir, + ), + 'app' => array( + 'debug' => true, + ), + )); $app = require 'boot.php'; - $app['debug'] = true; - $app['git.repos'] = self::$tmpdir; return $app; } From 54e2621333ee17dfcaa9dbb7bb905e123aaad77e Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 18:49:49 +0100 Subject: [PATCH 12/14] Added nested repository to fixtures. --- tests/InterfaceTest.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index d56f6b2..244e9b7 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -60,6 +60,18 @@ class InterfaceTest extends WebTestCase $repository->setConfig('user.email', 'luke@rebel.org'); $repository->addAll(); $repository->commit("First commit"); + + // Nested repository fixture + $nested_dir = self::$tmpdir . 'nested/'; + $fs->mkdir($nested_dir); + $git->createRepository($nested_dir . 'NestedRepo'); + $repository = $git->getRepository($nested_dir . '/NestedRepo'); + file_put_contents($nested_dir . 'NestedRepo/.git/description', 'This is a NESTED test repo!'); + file_put_contents($nested_dir . 'NestedRepo/README.txt', 'NESTED TEST REPO README'); + $repository->setConfig('user.name', 'Luke Skywalker'); + $repository->setConfig('user.email', 'luke@rebel.org'); + $repository->addAll(); + $repository->commit("First commit"); } public function createApplication() @@ -87,10 +99,12 @@ class InterfaceTest extends WebTestCase $this->assertCount(1, $crawler->filter('div.repository-header:contains("GitTest")')); $this->assertEquals('/GitTest/', $crawler->filter('.repository-header a')->eq(0)->attr('href')); $this->assertEquals('/GitTest/master/rss/', $crawler->filter('.repository-header a')->eq(1)->attr('href')); + $this->assertEquals('/nested/NestedRepo/', $crawler->filter('.repository-header a')->eq(2)->attr('href')); + $this->assertEquals('/nested/NestedRepo/master/rss/', $crawler->filter('.repository-header a')->eq(3)->attr('href')); $this->assertCount(1, $crawler->filter('div.repository-header:contains("foobar")')); $this->assertCount(1, $crawler->filter('div.repository-body:contains("This is a test repo!")')); - $this->assertEquals('/foobar/', $crawler->filter('.repository-header a')->eq(2)->attr('href')); - $this->assertEquals('/foobar/master/rss/', $crawler->filter('.repository-header a')->eq(3)->attr('href')); + $this->assertEquals('/foobar/', $crawler->filter('.repository-header a')->eq(4)->attr('href')); + $this->assertEquals('/foobar/master/rss/', $crawler->filter('.repository-header a')->eq(5)->attr('href')); } public function testRepositoryPage() From 2b43be92b3c7fccbba780f34348ece41f874d27e Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 19:09:29 +0100 Subject: [PATCH 13/14] Add unit tests for nested repository --- tests/InterfaceTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 244e9b7..d475158 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -72,6 +72,13 @@ class InterfaceTest extends WebTestCase $repository->setConfig('user.email', 'luke@rebel.org'); $repository->addAll(); $repository->commit("First commit"); + $repository->createBranch("testing"); + $repository->checkout("testing"); + file_put_contents($nested_dir . 'NestedRepo/README.txt', 'NESTED TEST BRANCH README'); + $repository->addAll(); + $repository->commit("Changing branch"); + $repository->checkout("master"); + } public function createApplication() @@ -225,6 +232,24 @@ class InterfaceTest extends WebTestCase $this->assertRegexp('/Initial commit/', $client->getResponse()->getContent()); } + public function testNestedRepoPage() + { + $client = $this->createClient(); + + $crawler = $client->request('GET', '/nested/NestedRepo/'); + $this->assertTrue($client->getResponse()->isOk()); + $this->assertRegexp('/NESTED TEST REPO README/', $client->getResponse()->getContent()); + } + + public function testNestedRepoBranch() + { + $client = $this->createClient(); + + $crawler = $client->request('GET', '/nested/NestedRepo/testing/'); + $this->assertTrue($client->getResponse()->isOk()); + $this->assertRegexp('/NESTED TEST BRANCH README/', $client->getResponse()->getContent()); + } + public static function tearDownAfterClass() { $fs = new Filesystem(); From 11e662c707f6e324d66a280bce3a633795734b3a Mon Sep 17 00:00:00 2001 From: Christian Schorn Date: Wed, 31 Oct 2012 19:32:00 +0100 Subject: [PATCH 14/14] Coding style - camelCase for variables --- src/GitList/Controller/MainController.php | 2 +- src/GitList/Util/Routing.php | 18 +++++++++--------- tests/InterfaceTest.php | 6 +++--- views/index.twig | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index a223721..89b6f62 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -15,7 +15,7 @@ class MainController implements ControllerProviderInterface $route->get('/', function() use ($app) { $repositories = array_map( function ($repo) use ($app) { - $repo['relative_path'] = $app['util.routing']->getRelativePath($repo['path']); + $repo['relativePath'] = $app['util.routing']->getRelativePath($repo['path']); return $repo; }, $app['git']->getRepositories($app['git.repos']) diff --git a/src/GitList/Util/Routing.php b/src/GitList/Util/Routing.php index 0f22dae..884e251 100644 --- a/src/GitList/Util/Routing.php +++ b/src/GitList/Util/Routing.php @@ -19,14 +19,14 @@ class Routing if ($regex === null) { $app = $this->app; - $quoted_paths = array_map( + $quotedPaths = array_map( function ($repo) use ($app) { return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); }, $this->app['git']->getRepositories($this->app['git.repos']) ); - usort($quoted_paths, function ($a, $b) { return strlen($b) - strlen($a); }); - $regex = implode('|', $quoted_paths); + usort($quotedPaths, function ($a, $b) { return strlen($b) - strlen($a); }); + $regex = implode('|', $quotedPaths); } return $regex; @@ -35,17 +35,17 @@ class Routing /** * Strips the base path from a full repository path * - * @param string $repo_path Full path to the repository + * @param string $repoPath Full path to the repository * @return string Relative path to the repository from git.repositories */ - public function getRelativePath($repo_path) + public function getRelativePath($repoPath) { - if (strpos($repo_path, $this->app['git.repos']) === 0) { - $relative_path = substr($repo_path, strlen($this->app['git.repos'])); - return ltrim($relative_path, '/'); + if (strpos($repoPath, $this->app['git.repos']) === 0) { + $relativePath = substr($repoPath, strlen($this->app['git.repos'])); + return ltrim($relativePath, '/'); } else { throw new \InvalidArgumentException( - sprintf("Path '%s' does not match configured repository directory", $repo_path) + sprintf("Path '%s' does not match configured repository directory", $repoPath) ); } } diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index d475158..38e437d 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -7,7 +7,7 @@ use Gitter\Client; class InterfaceTest extends WebTestCase { protected static $tmpdir; - protected static $git_path; + protected static $gitPath; public static function setUpBeforeClass() { @@ -32,7 +32,7 @@ class InterfaceTest extends WebTestCase $options['hidden'] = array(self::$tmpdir . '/hiddenrepo'); $git = new Client($options); - self::$git_path = $options['path']; + self::$gitPath = $options['path']; // GitTest repository fixture $git->createRepository(self::$tmpdir . 'GitTest'); @@ -85,7 +85,7 @@ class InterfaceTest extends WebTestCase { $config = new \GitList\Config(array( 'git' => array( - 'client' => self::$git_path, + 'client' => self::$gitPath, 'repositories' => self::$tmpdir, ), 'app' => array( diff --git a/views/index.twig b/views/index.twig index 898fd20..07093cd 100644 --- a/views/index.twig +++ b/views/index.twig @@ -9,8 +9,8 @@ {% for repository in repositories %}

{{ repository.description }}