From 35dd1ed08448e050ce6de654a666cde41f33b4e2 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Sun, 5 May 2013 23:16:51 -0300 Subject: [PATCH] Prevent 404 in case the repository in empty, create a proper error. Fixes #305 --- src/GitList/Exception/BlankDataException.php | 5 ++++- src/GitList/Exception/EmptyRepositoryException.php | 8 ++++++++ src/GitList/Util/Routing.php | 11 +++++------ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/GitList/Exception/EmptyRepositoryException.php diff --git a/src/GitList/Exception/BlankDataException.php b/src/GitList/Exception/BlankDataException.php index f11fb4e..1293fbb 100644 --- a/src/GitList/Exception/BlankDataException.php +++ b/src/GitList/Exception/BlankDataException.php @@ -2,4 +2,7 @@ namespace GitList\Exception; -class BlankDataException extends \RuntimeException {} +class BlankDataException extends \RuntimeException +{ + +} diff --git a/src/GitList/Exception/EmptyRepositoryException.php b/src/GitList/Exception/EmptyRepositoryException.php new file mode 100644 index 0000000..027a4d7 --- /dev/null +++ b/src/GitList/Exception/EmptyRepositoryException.php @@ -0,0 +1,8 @@ +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);