Prevent 404 in case the repository in empty, create a proper error. Fixes #305

This commit is contained in:
Klaus Silveira
2013-05-05 23:16:51 -03:00
parent 89bc96b4e0
commit 35dd1ed084
3 changed files with 17 additions and 7 deletions

View File

@@ -2,4 +2,7 @@
namespace GitList\Exception;
class BlankDataException extends \RuntimeException {}
class BlankDataException extends \RuntimeException
{
}

View File

@@ -0,0 +1,8 @@
<?php
namespace GitList\Exception;
class EmptyRepositoryException extends \RuntimeException
{
}

View File

@@ -3,6 +3,7 @@
namespace GitList\Util;
use Silex\Application;
use GitList\Exception\EmptyRepositoryException;
class Routing
{
@@ -40,8 +41,6 @@ class Routing
}
if ($commitish === null) {
// DEBUG Can you have a repo with no branches? How should we handle
// that?
$branches = $repository->getBranches();
$tags = $repository->getTags();
@@ -59,11 +58,11 @@ class Routing
}
}
$commitish = $matchedBranch;
}
if ($matchedBranch === null) {
throw new EmptyRepositoryException('This repository is currently empty. There are no commits.');
}
if ($commitish === null) {
$app->abort(404, "'$branch_path' does not appear to contain a commit-ish for '$repo'.");
$commitish = $matchedBranch;
}
$commitishLength = strlen($commitish);