Solving conflicts

This commit is contained in:
Klaus Silveira
2013-01-17 14:15:28 -02:00
5 changed files with 45 additions and 7 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;
@@ -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,
));

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

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

View File

@@ -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', "<?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()
@@ -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();

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>