Implementing hidden repository feature, fixes #30

This commit is contained in:
Klaus Silveira
2012-06-07 01:34:22 -03:00
parent a76e8f858e
commit 167c5b83cc
4 changed files with 26 additions and 5 deletions

View File

@@ -1,6 +1,14 @@
[git] [git]
client = '/usr/bin/git' ; Your git executable path client = '/usr/bin/git' ; Your git executable path
repositories = '/home/git/' ; Path to your repositories (with ending slash) repositories = '/var/www/projects/' ; Path to your repositories (with ending slash)
; You can hide repositories from GitList, just copy this for each repository you want to hide
; hidden[] = '/var/www/projects/BetaTest'
[app] [app]
baseurl = 'http://localhost/gitlist' ; Base URL of the application (without ending slash) baseurl = 'http://localhost/git' ; Base URL of the application (without ending slash)
; If you need to specify custom filetypes for certain extensions, do this here
[filetypes]
; extension = type
; dist = xml

View File

@@ -16,6 +16,7 @@ require_once __DIR__.'/vendor/silex.phar';
$app = new Silex\Application(); $app = new Silex\Application();
$app['baseurl'] = $config['app']['baseurl']; $app['baseurl'] = $config['app']['baseurl'];
$app['filetypes'] = $config['filetypes']; $app['filetypes'] = $config['filetypes'];
$app['hidden'] = isset($config['git']['hidden']) ? $config['git']['hidden'] : array();
// Register Git and Twig libraries // Register Git and Twig libraries
$app['autoloader']->registerNamespace('Git', __DIR__.'/lib'); $app['autoloader']->registerNamespace('Git', __DIR__.'/lib');

View File

@@ -2,12 +2,17 @@
namespace Git; namespace Git;
use Silex\Application;
class Client class Client
{ {
protected $app;
protected $path; protected $path;
public function __construct($path) public function __construct(Application $app)
{ {
$this->app = $app;
$path = $this->app['git.client'] ? $this->app['git.client'] : '/usr/bin/git';
$this->setPath($path); $this->setPath($path);
} }
@@ -39,6 +44,10 @@ class Client
throw new \RuntimeException('There is no GIT repository at ' . $path); throw new \RuntimeException('There is no GIT repository at ' . $path);
} }
if (in_array($path, $this->app['hidden'])) {
throw new \RuntimeException('You don\'t have access to this repository');
}
return new Repository($path, $this); return new Repository($path, $this);
} }
@@ -80,6 +89,10 @@ class Client
$isRepository = file_exists($file->getPathname() . '/.git/HEAD'); $isRepository = file_exists($file->getPathname() . '/.git/HEAD');
if ($file->isDir() && $isRepository || $isBare) { if ($file->isDir() && $isRepository || $isBare) {
if (in_array($file->getPathname(), $this->app['hidden'])) {
continue;
}
if ($isBare) { if ($isBare) {
$description = $file->getPathname() . '/description'; $description = $file->getPathname() . '/description';
} else { } else {

View File

@@ -16,8 +16,7 @@ class GitServiceProvider implements ServiceProviderInterface
public function register(Application $app) public function register(Application $app)
{ {
$app['git'] = function () use ($app) { $app['git'] = function () use ($app) {
$default = $app['git.client'] ? $app['git.client'] : '/usr/bin/git'; return new Client($app);
return new Client($app['git.client']);
}; };
} }
} }