Use checked-out branch as default branch.

Previously assumed 'master' was the default branch, when master may not
exist at all.
This commit is contained in:
Nate Eagleson
2012-12-13 15:41:52 -05:00
parent 44ed193402
commit 0fa349476a
5 changed files with 39 additions and 6 deletions

View File

@@ -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,
));

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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', "<?php\necho 'Hello World'; // This is a test");
$repository->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();

View File

@@ -10,7 +10,7 @@
<div class="repository">
<div class="repository-header">
<i class="icon-folder-open icon-spaced"></i> <a href="{{ path('repository', {repo: repository.relativePath}) }}">{{ repository.name }}</a>
<a href="{{ path('rss', {repo: repository.relativePath, branch: 'master'}) }}"><i class="rss pull-right"></i></a>
<a href="{{ path('rss', {repo: repository.relativePath, branch: repository.branch }) }}"><i class="rss pull-right"></i></a>
</div>
<div class="repository-body">
<p>{{ repository.description }}</p>