diff --git a/.gitignore b/.gitignore index 5b201dc..6bcba4c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ nbproject .CVS .idea node_modules +config.ini diff --git a/README.md b/README.md index 4647e9a..748f2e5 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Download the GitList latest package and decompress to your `/var/www/gitlist` fo git clone https://github.com/klaussilveira/gitlist.git /var/www/gitlist ``` -Now open up the `config.ini` and configure your installation. You'll have to provide where your repositories are located and the base GitList URL (in our case, http://localhost/gitlist). Now, let's create the cache folder and give the correct permissions: +Rename the `config.ini-example` file to `config.ini`. Now open up the `config.ini` and configure your installation. You'll have to provide where your repositories are located and the base GitList URL (in our case, http://localhost/gitlist). Now, let's create the cache folder and give the correct permissions: ``` cd /var/www/gitlist diff --git a/config.ini b/config.ini deleted file mode 100644 index 186c20d..0000000 --- a/config.ini +++ /dev/null @@ -1,6 +0,0 @@ -[git] -client = '/usr/bin/git' ; Your git executable path -repositories = '/home/git/' ; Path to your repositories (with ending slash) - -[app] -baseurl = 'http://localhost/gitlist' ; Base URL of the application (without ending slash) diff --git a/config.ini-example b/config.ini-example new file mode 100644 index 0000000..fc99be3 --- /dev/null +++ b/config.ini-example @@ -0,0 +1,14 @@ +[git] +client = '/usr/bin/git' ; Your git executable path +repositories = '/var/www/projects/' ; Path to your repositories + +; You can hide repositories from GitList, just copy this for each repository you want to hide +; hidden[] = '/var/www/projects/BetaTest' + +[app] +baseurl = 'http://localhost/git' ; Base URL of the application + +; If you need to specify custom filetypes for certain extensions, do this here +[filetypes] +; extension = type +; dist = xml \ No newline at end of file diff --git a/index.php b/index.php index 037f878..c9147cf 100644 --- a/index.php +++ b/index.php @@ -7,14 +7,17 @@ $config = parse_ini_file('config.ini', true); -if (empty($config['git']['repositories'])) { +if (empty($config['git']['repositories']) || !is_dir($config['git']['repositories'])) { die("Please, edit the config.ini file and provide your repositories directory"); } -require_once __DIR__.'/vendor/silex.phar'; +require_once 'phar://'.__DIR__.'/vendor/silex.phar'; $app = new Silex\Application(); -$app['baseurl'] = $config['app']['baseurl']; +$app['baseurl'] = rtrim($config['app']['baseurl'], '/'); +$app['filetypes'] = $config['filetypes']; +$app['hidden'] = isset($config['git']['hidden']) ? $config['git']['hidden'] : array(); +$config['git']['repositories'] = rtrim($config['git']['repositories'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; // Register Git and Twig libraries $app['autoloader']->registerNamespace('Git', __DIR__.'/lib'); diff --git a/lib/Application/Utils.php b/lib/Application/Utils.php index f844e6d..78767a6 100644 --- a/lib/Application/Utils.php +++ b/lib/Application/Utils.php @@ -2,11 +2,20 @@ namespace Application; +use Silex\Application; + /** * General helper class, mostly used for string parsing inside the application controllers */ class Utils { + protected $app; + + public function __construct(Application $app) + { + $this->app = $app; + } + /** * Builds a breadcrumb array based on a path spec * @@ -209,8 +218,14 @@ class Utils return 'image'; case 'bmp': return 'image'; - default: - return 'text'; + } + + if (!empty($this->app['filetypes'])) { + foreach ($this->app['filetypes'] as $ext => $type) { + if ($fileType == $ext) { + return $type; + } + } } } diff --git a/lib/Application/UtilsServiceProvider.php b/lib/Application/UtilsServiceProvider.php index 2be4370..20d5367 100644 --- a/lib/Application/UtilsServiceProvider.php +++ b/lib/Application/UtilsServiceProvider.php @@ -16,7 +16,7 @@ class UtilsServiceProvider implements ServiceProviderInterface public function register(Application $app) { $app['utils'] = function () use ($app) { - return new Utils; + return new Utils($app); }; } } \ No newline at end of file diff --git a/lib/Git/Client.php b/lib/Git/Client.php index 960f5d6..252e636 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -2,12 +2,17 @@ namespace Git; +use Silex\Application; + class Client { + protected $app; 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); } @@ -39,6 +44,10 @@ class Client 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); } @@ -80,10 +89,20 @@ class Client $isRepository = file_exists($file->getPathname() . '/.git/HEAD'); if ($file->isDir() && $isRepository || $isBare) { + if (in_array($file->getPathname(), $this->app['hidden'])) { + continue; + } + if ($isBare) { - $description = file_get_contents($file->getPathname() . '/description'); + $description = $file->getPathname() . '/description'; } else { - $description = file_get_contents($file->getPathname() . '/.git/description'); + $description = $file->getPathname() . '/.git/description'; + } + + if (file_exists($description)) { + $description = file_get_contents($description); + } else { + $description = 'There is no repository description file. Please, create one to remove this message.'; } $repositories[] = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'description' => $description); diff --git a/lib/Git/GitServiceProvider.php b/lib/Git/GitServiceProvider.php index 1e8ab6d..558915e 100644 --- a/lib/Git/GitServiceProvider.php +++ b/lib/Git/GitServiceProvider.php @@ -16,8 +16,7 @@ class GitServiceProvider implements ServiceProviderInterface public function register(Application $app) { $app['git'] = function () use ($app) { - $default = $app['git.client'] ? $app['git.client'] : '/usr/bin/git'; - return new Client($app['git.client']); + return new Client($app); }; } } \ No newline at end of file diff --git a/lib/Git/Model/Diff.php b/lib/Git/Model/Diff.php index 17fa0e6..f20abb0 100644 --- a/lib/Git/Model/Diff.php +++ b/lib/Git/Model/Diff.php @@ -45,7 +45,6 @@ class Diff public function setNew($new) { $this->new = $new; - $this->file = substr($new, 6); } public function getNew() @@ -53,6 +52,11 @@ class Diff return $this->new; } + public function setFile($file) + { + $this->file = $file; + } + public function getFile() { return $this->file; diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index 1db38f3..2b930f4 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -224,12 +224,14 @@ class Repository */ public function getTotalCommits($file = null) { - $command = "rev-list --all --count"; + $command = "rev-list --all"; if ($file) { $command .= " $file"; } + $command .= " | wc -l"; + $commits = $this->getClient()->run($this, $command); return $commits; } @@ -331,6 +333,10 @@ class Repository $commit->importData($data); unset($logs[0]); + if (empty($logs[1])) { + throw new \RuntimeException('No commit log available'); + } + // Read diff logs foreach ($logs as $log) { if ('diff' === substr($log, 0, 4)) { @@ -339,6 +345,8 @@ class Repository } $diff = new Diff; + preg_match('/^diff --[\S]+ (a\/)?([\S]+)( b\/)?/', $log, $name); + $diff->setFile($name[2]); continue; } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 69e7f28..9b81699 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -1,5 +1,7 @@ markTestSkipped('There are no write permissions in order to create test repositories.'); } - $this->client = new Client('/usr/bin/git'); + $app = new Silex\Application(); + $app['git.client'] = '/usr/bin/git'; + $app['hidden'] = array(); + $this->client = new Client($app); } /** diff --git a/views/index.twig b/views/index.twig index 5b23f45..2a594b3 100644 --- a/views/index.twig +++ b/views/index.twig @@ -1,5 +1,5 @@ {% extends 'layout.twig' %} -{% block title %}Gitlist{% endblock %} +{% block title %}GitList{% endblock %} {% block body %} {% include 'navigation.twig' %}