mirror of
https://github.com/klaussilveira/gitlist.git
synced 2026-05-07 14:16:19 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,3 +26,4 @@ nbproject
|
||||
.CVS
|
||||
.idea
|
||||
node_modules
|
||||
config.ini
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
14
config.ini-example
Normal file
14
config.ini-example
Normal file
@@ -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
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../vendor/silex.phar';
|
||||
|
||||
use Git\Client;
|
||||
use Git\Repository;
|
||||
|
||||
@@ -52,7 +54,10 @@ class ClientTest extends PHPUnit_Framework_TestCase
|
||||
$this->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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends 'layout.twig' %}
|
||||
{% block title %}Gitlist{% endblock %}
|
||||
{% block title %}GitList{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{% include 'navigation.twig' %}
|
||||
|
||||
Reference in New Issue
Block a user