diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 2597556..2383ccf 100644 --- a/src/GitList/Controller/CommitController.php +++ b/src/GitList/Controller/CommitController.php @@ -15,6 +15,10 @@ class CommitController implements ControllerProviderInterface $route->get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); + if ($branch === null) { + $branch = $repository->getHead(); + } + list($branch, $file) = $app['util.repository']->extractRef($repository, $branch, $file); $type = $file ? "$branch -- \"$file\"" : $branch; @@ -43,7 +47,7 @@ class CommitController implements ControllerProviderInterface })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') ->assert('file', '.+') - ->value('branch', 'master') + ->value('branch', null) ->value('file', '') ->bind('commits'); @@ -75,9 +79,10 @@ class CommitController implements ControllerProviderInterface $route->get('{repo}/commit/{commit}', function($repo, $commit) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $commit = $repository->getCommit($commit); + $branch = $repository->getHead(); return $app['twig']->render('commit.twig', array( - 'branch' => 'master', + 'branch' => $branch, 'repo' => $repo, 'commit' => $commit, )); diff --git a/src/GitList/Controller/MainController.php b/src/GitList/Controller/MainController.php index 89b6f62..3262b04 100644 --- a/src/GitList/Controller/MainController.php +++ b/src/GitList/Controller/MainController.php @@ -16,6 +16,9 @@ class MainController implements ControllerProviderInterface $repositories = array_map( function ($repo) use ($app) { $repo['relativePath'] = $app['util.routing']->getRelativePath($repo['path']); + $repository = $app['git']->getRepository($repo['path']); + $repo['branch'] = $repository->getHead(); + return $repo; }, $app['git']->getRepositories($app['git.repos']) @@ -28,6 +31,9 @@ class MainController implements ControllerProviderInterface $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); + if ($branch === null) { + $branch = $repository->getHead(); + } $stats = $repository->getStatistics($branch); $authors = $repository->getAuthorStatistics(); @@ -41,7 +47,7 @@ class MainController implements ControllerProviderInterface )); })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', '[\w-._\/]+') - ->value('branch', 'master') + ->value('branch', null) ->bind('stats'); $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 5659125..206c757 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -161,9 +161,12 @@ class Repository return false; } - public function getReadme($repo, $branch = 'master') + public function getReadme($repo, $branch = null) { $repository = $this->app['git']->getRepository($this->app['git.repos'] . $repo); + if ($branch === null) { + $branch = $repository->getHead(); + } $files = $repository->getTree($branch)->output(); foreach ($files as $file) { diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 38e437d..99a97b9 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -79,6 +79,22 @@ class InterfaceTest extends WebTestCase $repository->commit("Changing branch"); $repository->checkout("master"); + // master-less repository fixture + $git->createRepository(self::$tmpdir . 'develop'); + $repository = $git->getRepository(self::$tmpdir . '/develop'); + $repository->setConfig('user.name', 'Luke Skywalker'); + $repository->setConfig('user.email', 'luke@rebel.org'); + file_put_contents(self::$tmpdir . 'develop/README.md', "## develop\ndevelop is a *test* repository!"); + $repository->addAll(); + $repository->commit("First commit"); + $repository->createBranch("develop"); + $repository = $repository->checkout('develop'); + + file_put_contents(self::$tmpdir . 'develop/test.php', "setConfig('user.name', 'Luke Skywalker'); + $repository->setConfig('user.email', 'luke@rebel.org'); + $repository->addAll(); + $repository->commit("Initial commit"); } public function createApplication() @@ -110,8 +126,8 @@ class InterfaceTest extends WebTestCase $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(4)->attr('href')); - $this->assertEquals('/foobar/master/rss/', $crawler->filter('.repository-header a')->eq(5)->attr('href')); + $this->assertEquals('/foobar/', $crawler->filter('.repository-header a')->eq(6)->attr('href')); + $this->assertEquals('/foobar/master/rss/', $crawler->filter('.repository-header a')->eq(7)->attr('href')); } public function testRepositoryPage() @@ -241,6 +257,14 @@ class InterfaceTest extends WebTestCase $this->assertRegexp('/NESTED TEST REPO README/', $client->getResponse()->getContent()); } + public function testDevelopRepo() + { + $client = $this->createClient(); + + $crawler = $client->request('GET', '/develop/'); + $this->assertTrue($client->getResponse()->isOk()); + } + public function testNestedRepoBranch() { $client = $this->createClient(); diff --git a/views/index.twig b/views/index.twig index 07093cd..b3f075d 100644 --- a/views/index.twig +++ b/views/index.twig @@ -10,7 +10,7 @@
{{ repository.name }} - +

{{ repository.description }}