diff --git a/boot.php b/boot.php index 9b84f04..dd33f5b 100644 --- a/boot.php +++ b/boot.php @@ -4,32 +4,17 @@ if (!isset($config)) { die("No configuration object provided."); } -$repositories = $config->get('git', 'repositories'); - -if (!is_array($repositories)) { - # Convert the single item to an array - this is the internal handling - $repositories = array($repositories); +if (!is_writable(__DIR__ . DIRECTORY_SEPARATOR . 'cache')) { + die(sprintf('The "%s" folder must be writable for GitList to run.', __DIR__ . DIRECTORY_SEPARATOR . 'cache')); } -$tmp_arr = array(); -foreach ($repositories as $repo) { - $tmp = rtrim($repo, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; - $tmp_arr []= $tmp; -} -$repositories = $tmp_arr; - - - // Startup and configure Silex application $app = new GitList\Application($config, __DIR__); - // Mount the controllers $app->mount('', new GitList\Controller\MainController()); $app->mount('', new GitList\Controller\BlobController()); $app->mount('', new GitList\Controller\CommitController()); $app->mount('', new GitList\Controller\TreeController()); - return $app; - diff --git a/build.xml b/build.xml index 23469f3..fcb1916 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - - + + @@ -10,15 +10,18 @@ + - + + + @@ -75,15 +78,25 @@ + + + + + + + + + - + - diff --git a/src/GitList/Application.php b/src/GitList/Application.php index ced3505..acebc36 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -15,6 +15,8 @@ use GitList\Provider\RoutingUtilServiceProvider; */ class Application extends SilexApplication { + protected $path; + /** * Constructor initialize services. * @@ -24,44 +26,35 @@ class Application extends SilexApplication public function __construct(Config $config, $root = null) { parent::__construct(); - $app = $this; - $root = realpath($root); + $this->path = realpath($root); $this['debug'] = $config->get('app', 'debug'); $this['filetypes'] = $config->getSection('filetypes'); - $this['cache.archives'] = $root . DIRECTORY_SEPARATOR - . 'cache' . DIRECTORY_SEPARATOR . 'archives'; + $this['cache.archives'] = $this->getCachePath() . 'archives'; // Register services $this->register(new TwigServiceProvider(), array( - 'twig.path' => $root . DIRECTORY_SEPARATOR . 'views', - 'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR - . 'cache' . DIRECTORY_SEPARATOR . 'views'), + 'twig.path' => $this->getViewPath(), + 'twig.options' => array('cache' => $this->getCachePath() . 'views'), )); $repositories = $config->get('git', 'repositories'); - - $cached_repos = $config->get('app', 'cached_repos'); - if (false === $cached_repos || empty($cached_repos)) { - $cached_repos = $root . DIRECTORY_SEPARATOR . 'cache' - . DIRECTORY_SEPARATOR . 'repos.json'; + $repositoryCache = $config->get('app', 'cached_repos'); + if (false === $repositoryCache || empty($repositoryCache)) { + $repositoryCache = $this->getCachePath() . 'repos.json'; } $this->register(new GitServiceProvider(), array( 'git.client' => $config->get('git', 'client'), 'git.repos' => $repositories, - 'cache.repos' => $cached_repos, + 'cache.repos' => $repositoryCache, 'ini.file' => "config.ini", 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(), 'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master', )); - $cached_repos = $root . DIRECTORY_SEPARATOR . - 'cache' . DIRECTORY_SEPARATOR . 'repos.json'; - - $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); @@ -74,7 +67,6 @@ class Application extends SilexApplication return $twig; })); - // Handle errors $this->error(function (\Exception $e, $code) use ($app) { if ($app['debug']) { @@ -86,5 +78,26 @@ class Application extends SilexApplication )); }); } + + public function getPath() + { + return $this->path . DIRECTORY_SEPARATOR; + } + + public function setPath($path) + { + $this->path = $path; + return $this; + } + + public function getCachePath() + { + return $this->path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; + } + + public function getViewPath() + { + return $this->path . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR; + } } 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); @@ -72,11 +71,6 @@ class Routing $path = substr($path, 1); } - $commitHasPath = $repository->pathExists($commitish, $path); - if ($commitHasPath !== true) { - $app->abort(404, "\"$path\" does not exist in \"$commitish\"."); - } - return array($commitish, $path); } diff --git a/views/tree.twig b/views/tree.twig index 9dfa8a5..a33bbb4 100644 --- a/views/tree.twig +++ b/views/tree.twig @@ -17,6 +17,7 @@ {% endblock %} {% endembed %} + {% if files is not empty %} @@ -54,6 +55,9 @@ {% endfor %}
+ {% else %} +

This repository is empty.

+ {% endif %} {% if readme is defined and readme is not empty %}