diff --git a/src/GitList/Controller/CommitController.php b/src/GitList/Controller/CommitController.php index 776f669..d215074 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; @@ -41,12 +45,13 @@ 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'); $route->post('{repo}/commits/search', function(Request $request, $repo) use ($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $branch = $repository->getHead(); $commits = $repository->searchCommitLog($request->get('query')); foreach ($commits as $commit) { @@ -57,7 +62,7 @@ class CommitController implements ControllerProviderInterface return $app['twig']->render('searchcommits.twig', array( 'repo' => $repo, - 'branch' => 'master', + 'branch' => $branch, 'file' => '', 'commits' => $categorized, 'branches' => $repository->getBranches(), @@ -69,9 +74,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 e158b95..169ea9c 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -160,9 +160,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..132d960 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -79,6 +79,16 @@ class InterfaceTest extends WebTestCase $repository->commit("Changing branch"); $repository->checkout("master"); + // master-less repository fixture + $git->createRepository(self::$tmpdir . 'masterless'); + $repository = $git->getRepository(self::$tmpdir . 'masterless'); + $repository = $repository->checkout('develop'); + file_put_contents(self::$tmpdir . 'masterless/README.md', "## masterless\nmasterless is a *test* repository!"); + file_put_contents(self::$tmpdir . 'masterless/test.php', "setConfig('user.name', 'Luke Skywalker'); + $repository->setConfig('user.email', 'luke@rebel.org'); + $repository->addAll(); + $repository->commit("Initial commit"); } public function createApplication() @@ -241,6 +251,14 @@ class InterfaceTest extends WebTestCase $this->assertRegexp('/NESTED TEST REPO README/', $client->getResponse()->getContent()); } + public function testMasterlessRepo() + { + $client = $this->createClient(); + + $crawler = $client->request('GET', '/masterless/'); + $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 }}