From 3e9f428d1b100d3e8291cade7ece27df6678f7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Prochowski?= Date: Mon, 4 Jun 2012 02:51:05 +0200 Subject: [PATCH 01/15] Change config.ini to config.ini-example and add config.ini to .gitignore --- .gitignore | 1 + config.ini => config.ini-example | 0 2 files changed, 1 insertion(+) rename config.ini => config.ini-example (100%) 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/config.ini b/config.ini-example similarity index 100% rename from config.ini rename to config.ini-example From feefd0457780b48fa9c6ad760b5c4d0635bc0a77 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Mon, 4 Jun 2012 12:44:11 -0300 Subject: [PATCH 02/15] Update master --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ab14e90cddf8c005b66f53635d7c7228cbdcd735 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Mon, 4 Jun 2012 15:22:10 -0300 Subject: [PATCH 03/15] Update master --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 748f2e5..f60fcaf 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You can also see a live demo [here](http://git.gofedora.com). ## Requirements In order to run GitList on your server, you'll need: -* git +* git 1.7.6 or higher * Apache and mod_rewrite enabled * PHP 5.3.3 From 8ac31cdc930338b8d824a69f5be95ade8e189a8f Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 00:55:56 -0300 Subject: [PATCH 04/15] Adding support to syntax highlighting for custom extensions, fixes #34. Thanks @attiks --- index.php | 1 + lib/Application/Utils.php | 19 +++++++++++++++++-- lib/Application/UtilsServiceProvider.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 037f878..a2d1e8a 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,7 @@ require_once __DIR__.'/vendor/silex.phar'; $app = new Silex\Application(); $app['baseurl'] = $config['app']['baseurl']; +$app['filetypes'] = $config['filetypes']; // 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 From a76e8f858e938cd8ea0886fe49ec238ea4fc6b8b Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 01:15:53 -0300 Subject: [PATCH 05/15] Treat non-existing description file on repositories, fixes #41 --- lib/Git/Client.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Git/Client.php b/lib/Git/Client.php index 960f5d6..f24057b 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -81,9 +81,15 @@ class Client if ($file->isDir() && $isRepository || $isBare) { 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); From 167c5b83cc4eb8eb66b57569393c5fa7e10a6578 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 01:34:22 -0300 Subject: [PATCH 06/15] Implementing hidden repository feature, fixes #30 --- config.ini-example | 12 ++++++++++-- index.php | 1 + lib/Git/Client.php | 15 ++++++++++++++- lib/Git/GitServiceProvider.php | 3 +-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/config.ini-example b/config.ini-example index 186c20d..0684768 100644 --- a/config.ini-example +++ b/config.ini-example @@ -1,6 +1,14 @@ [git] 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] -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 \ No newline at end of file diff --git a/index.php b/index.php index a2d1e8a..5ef54ef 100644 --- a/index.php +++ b/index.php @@ -16,6 +16,7 @@ require_once __DIR__.'/vendor/silex.phar'; $app = new Silex\Application(); $app['baseurl'] = $config['app']['baseurl']; $app['filetypes'] = $config['filetypes']; +$app['hidden'] = isset($config['git']['hidden']) ? $config['git']['hidden'] : array(); // Register Git and Twig libraries $app['autoloader']->registerNamespace('Git', __DIR__.'/lib'); diff --git a/lib/Git/Client.php b/lib/Git/Client.php index f24057b..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,6 +89,10 @@ 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->getPathname() . '/description'; } else { 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 From ec85e90e84a7074f1be9b4c5247e3d436a992422 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 01:40:28 -0300 Subject: [PATCH 07/15] Fixing broken tests --- tests/ClientTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } /** From fbd79f256b2ac8f01613744bb96fd562861ff462 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 01:46:02 -0300 Subject: [PATCH 08/15] Dropped --count on rev-list in order to improve compatibility, using wc -l. Fixes #31 --- README.md | 2 +- lib/Git/Repository.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f60fcaf..748f2e5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You can also see a live demo [here](http://git.gofedora.com). ## Requirements In order to run GitList on your server, you'll need: -* git 1.7.6 or higher +* git * Apache and mod_rewrite enabled * PHP 5.3.3 diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index 1db38f3..c7f9544 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -224,7 +224,7 @@ class Repository */ public function getTotalCommits($file = null) { - $command = "rev-list --all --count"; + $command = "rev-list --all | wc -l"; if ($file) { $command .= " $file"; From 6aeb19c5babc974fc2ed7ec44a83946091a404fb Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 01:50:56 -0300 Subject: [PATCH 09/15] Fixing typo --- views/index.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' %} From df8f74a9cbac72df133ef5628dc9c07830300bfe Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 02:03:32 -0300 Subject: [PATCH 10/15] Fixing wc -l implementation on getTotalCommits --- lib/Git/Repository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index c7f9544..ec7d64d 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 | wc -l"; + $command = "rev-list --all"; if ($file) { $command .= " $file"; } + $command .= " | wc -l"; + $commits = $this->getClient()->run($this, $command); return $commits; } From 484c72679abc0827a0fdb568fe835d22df479eb0 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 02:32:30 -0300 Subject: [PATCH 11/15] Better filename handling in commit logs, fixes #35 --- lib/Git/Model/Diff.php | 6 +++++- lib/Git/Repository.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 ec7d64d..de453c4 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -341,6 +341,8 @@ class Repository } $diff = new Diff; + preg_match('/^diff --[\S]+ (a\/)?([\S]+)( b\/)?/', $log, $name); + $diff->setFile($name[2]); continue; } From 8092f9c3c8fc29dc34fc9b1b91abb9cb69eeb1bb Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 02:37:45 -0300 Subject: [PATCH 12/15] Better error handling in the commit log --- lib/Git/Repository.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Git/Repository.php b/lib/Git/Repository.php index de453c4..2b930f4 100644 --- a/lib/Git/Repository.php +++ b/lib/Git/Repository.php @@ -333,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)) { From 9e366378b0712dbe877ddbccc8cc8eb8673ee406 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 02:43:16 -0300 Subject: [PATCH 13/15] Verify repository folder existence before anything, fixes #44 --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 5ef54ef..93e6543 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ $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"); } From e1e0f867a0fbdf60704bfa2e18bed63c4e2facec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Sat, 9 Jun 2012 04:59:48 +0200 Subject: [PATCH 14/15] Make explicit the phar:// scheme --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 93e6543..4ba6b5c 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,7 @@ if (empty($config['git']['repositories']) || !is_dir($config['git']['repositorie 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']; From e57ada553e9dd173c8d10d46f07b02ee52def827 Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Sun, 10 Jun 2012 08:14:36 -0400 Subject: [PATCH 15/15] Litle tweaks for config.ini-example - tweak for git.repositories config to don't care "with ending slash" cond. - tweak for app.baseurl config to don't care "without ending slash" cond. --- config.ini-example | 6 +++--- index.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config.ini-example b/config.ini-example index 0684768..fc99be3 100644 --- a/config.ini-example +++ b/config.ini-example @@ -1,12 +1,12 @@ [git] client = '/usr/bin/git' ; Your git executable path -repositories = '/var/www/projects/' ; Path to your repositories (with ending slash) +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' +; hidden[] = '/var/www/projects/BetaTest' [app] -baseurl = 'http://localhost/git' ; Base URL of the application (without ending slash) +baseurl = 'http://localhost/git' ; Base URL of the application ; If you need to specify custom filetypes for certain extensions, do this here [filetypes] diff --git a/index.php b/index.php index 4ba6b5c..c9147cf 100644 --- a/index.php +++ b/index.php @@ -14,9 +14,10 @@ if (empty($config['git']['repositories']) || !is_dir($config['git']['repositorie 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');