mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 11:10:57 +01:00
Updating GitList to use Gitter
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
"silex/silex": "1.0.*",
|
"silex/silex": "1.0.*",
|
||||||
"twig/twig": "1.9.*",
|
"twig/twig": "1.9.*",
|
||||||
"symfony/twig-bridge": "2.1.*",
|
"symfony/twig-bridge": "2.1.*",
|
||||||
"symfony/filesystem": "2.1.*"
|
"symfony/filesystem": "2.1.*",
|
||||||
|
"klaussilveira/gitter": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/browser-kit": "2.1.*",
|
"symfony/browser-kit": "2.1.*",
|
||||||
|
|||||||
40
composer.lock
generated
40
composer.lock
generated
@@ -1,6 +1,12 @@
|
|||||||
{
|
{
|
||||||
"hash": "1790d6792c8544b8d1c9efbf8f5fe2de",
|
"hash": "9820789efd58e6b6bb6b746efb8500fe",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
{
|
||||||
|
"package": "klaussilveira/gitter",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source-reference": "209908f247194b1adc836f2e50f957cb1f11f41c",
|
||||||
|
"commit-date": "1347372763"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"package": "pimple/pimple",
|
"package": "pimple/pimple",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
@@ -10,8 +16,8 @@
|
|||||||
{
|
{
|
||||||
"package": "pimple/pimple",
|
"package": "pimple/pimple",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
"source-reference": "db836b8cfadc0f39dacafa2bf311a1ab603600bb",
|
"source-reference": "b9f27b8dc18c08f00627dec02359b46a24791dc3",
|
||||||
"commit-date": "1343051648"
|
"commit-date": "1347278988"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "silex/silex",
|
"package": "silex/silex",
|
||||||
@@ -22,14 +28,14 @@
|
|||||||
{
|
{
|
||||||
"package": "silex/silex",
|
"package": "silex/silex",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
"source-reference": "ad563dde113092aa603e2b399d10ea43aece8006",
|
"source-reference": "a9e34f08ab00c4cc6c97e7ae8fdf7d0fc367e5f5",
|
||||||
"commit-date": "1347084669"
|
"commit-date": "1347298149"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "symfony/event-dispatcher",
|
"package": "symfony/event-dispatcher",
|
||||||
"version": "2.1.x-dev",
|
"version": "2.1.x-dev",
|
||||||
"source-reference": "v2.1.0-RC2",
|
"source-reference": "v2.1.1",
|
||||||
"commit-date": "1345643321"
|
"commit-date": "1347274422"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "symfony/filesystem",
|
"package": "symfony/filesystem",
|
||||||
@@ -40,26 +46,32 @@
|
|||||||
{
|
{
|
||||||
"package": "symfony/http-foundation",
|
"package": "symfony/http-foundation",
|
||||||
"version": "2.1.x-dev",
|
"version": "2.1.x-dev",
|
||||||
"source-reference": "v2.1.0",
|
"source-reference": "v2.1.1",
|
||||||
"commit-date": "1346761482"
|
"commit-date": "1346761482"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "symfony/http-kernel",
|
"package": "symfony/http-kernel",
|
||||||
"version": "2.1.x-dev",
|
"version": "2.1.x-dev",
|
||||||
"source-reference": "ec5cdb100c20537e9d806facd4d121c985658e8b",
|
"source-reference": "584499e64026f41c4be938ed35d8f0a9a9eebd38",
|
||||||
"commit-date": "1346926323"
|
"commit-date": "1347354770"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"package": "symfony/process",
|
||||||
|
"version": "2.1.x-dev",
|
||||||
|
"source-reference": "v2.1.1",
|
||||||
|
"commit-date": "1346330945"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "symfony/routing",
|
"package": "symfony/routing",
|
||||||
"version": "2.1.x-dev",
|
"version": "2.1.x-dev",
|
||||||
"source-reference": "v2.1.0",
|
"source-reference": "v2.1.1",
|
||||||
"commit-date": "1346859854"
|
"commit-date": "1347274422"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "symfony/twig-bridge",
|
"package": "symfony/twig-bridge",
|
||||||
"version": "2.1.x-dev",
|
"version": "2.1.x-dev",
|
||||||
"source-reference": "v2.1.0",
|
"source-reference": "v2.1.1",
|
||||||
"commit-date": "1345643321"
|
"commit-date": "1347274422"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"package": "twig/twig",
|
"package": "twig/twig",
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="true"
|
||||||
syntaxCheck="true"
|
syntaxCheck="true"
|
||||||
|
bootstrap="./vendor/autoload.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="GitList Test Suite">
|
<testsuite name="GitList Test Suite">
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git;
|
|
||||||
|
|
||||||
use Silex\Application;
|
|
||||||
|
|
||||||
class Client
|
|
||||||
{
|
|
||||||
protected $path;
|
|
||||||
protected $hidden;
|
|
||||||
|
|
||||||
public function __construct($options = null)
|
|
||||||
{
|
|
||||||
$this->setPath($options['path']);
|
|
||||||
$this->setHidden($options['hidden']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new repository on the specified path
|
|
||||||
*
|
|
||||||
* @param string $path Path where the new repository will be created
|
|
||||||
* @return Repository Instance of Repository
|
|
||||||
*/
|
|
||||||
public function createRepository($path)
|
|
||||||
{
|
|
||||||
if (file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
|
|
||||||
throw new \RuntimeException('A GIT repository already exists at ' . $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$repository = new Repository($path, $this);
|
|
||||||
|
|
||||||
return $repository->create();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a repository at the specified path
|
|
||||||
*
|
|
||||||
* @param string $path Path where the repository is located
|
|
||||||
* @return Repository Instance of Repository
|
|
||||||
*/
|
|
||||||
public function getRepository($path)
|
|
||||||
{
|
|
||||||
if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
|
|
||||||
throw new \RuntimeException('There is no GIT repository at ' . $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($path, $this->getHidden())) {
|
|
||||||
throw new \RuntimeException('You don\'t have access to this repository');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Repository($path, $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for valid repositories on the specified path
|
|
||||||
*
|
|
||||||
* @param string $path Path where repositories will be searched
|
|
||||||
* @return array Found repositories, containing their name, path and description
|
|
||||||
*/
|
|
||||||
public function getRepositories($path)
|
|
||||||
{
|
|
||||||
$repositories = $this->recurseDirectory($path);
|
|
||||||
|
|
||||||
if (empty($repositories)) {
|
|
||||||
throw new \RuntimeException('There are no GIT repositories in ' . $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
sort($repositories);
|
|
||||||
|
|
||||||
return $repositories;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function recurseDirectory($path)
|
|
||||||
{
|
|
||||||
$dir = new \DirectoryIterator($path);
|
|
||||||
|
|
||||||
$repositories = array();
|
|
||||||
|
|
||||||
foreach ($dir as $file) {
|
|
||||||
if ($file->isDot()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($pos = strrpos($file->getFilename(), '.')) === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file->isDir()) {
|
|
||||||
$isBare = file_exists($file->getPathname() . '/HEAD');
|
|
||||||
$isRepository = file_exists($file->getPathname() . '/.git/HEAD');
|
|
||||||
|
|
||||||
if ($isRepository || $isBare) {
|
|
||||||
$pathName = str_replace('\\', '/', $file->getPathname());
|
|
||||||
|
|
||||||
if (in_array($pathName, $this->getHidden())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isBare) {
|
|
||||||
$description = $file->getPathname() . '/description';
|
|
||||||
} else {
|
|
||||||
$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' => $pathName, 'description' => $description);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $repositories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a git command on the repository being manipulated
|
|
||||||
*
|
|
||||||
* This method will start a new process on the current machine and
|
|
||||||
* run git commands. Once the command has been run, the method will
|
|
||||||
* return the command line output.
|
|
||||||
*
|
|
||||||
* @param Repository $repository Repository where the command will be run
|
|
||||||
* @param string $command Git command to be run
|
|
||||||
* @return string Returns the command output
|
|
||||||
*/
|
|
||||||
public function run(Repository $repository, $command)
|
|
||||||
{
|
|
||||||
$descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
|
|
||||||
$process = proc_open($this->getPath() . ' -c "color.ui"=false ' . $command, $descriptors, $pipes, $repository->getPath());
|
|
||||||
|
|
||||||
if (!is_resource($process)) {
|
|
||||||
throw new \RuntimeException('Unable to execute command: ' . $command);
|
|
||||||
}
|
|
||||||
|
|
||||||
$stdout = stream_get_contents($pipes[1]);
|
|
||||||
fclose($pipes[1]);
|
|
||||||
|
|
||||||
$stderr = stream_get_contents($pipes[2]);
|
|
||||||
fclose($pipes[2]);
|
|
||||||
|
|
||||||
$status = proc_close($process);
|
|
||||||
|
|
||||||
if ($status != 0) {
|
|
||||||
throw new \RuntimeException($stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stdout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current Git binary path
|
|
||||||
*
|
|
||||||
* @return string Path where the Git binary is located
|
|
||||||
*/
|
|
||||||
protected function getPath()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current Git binary path
|
|
||||||
*
|
|
||||||
* @param string $path Path where the Git binary is located
|
|
||||||
*/
|
|
||||||
protected function setPath($path)
|
|
||||||
{
|
|
||||||
$this->path = $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hidden repository list
|
|
||||||
*
|
|
||||||
* @return array List of repositories to hide
|
|
||||||
*/
|
|
||||||
protected function getHidden()
|
|
||||||
{
|
|
||||||
return $this->hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the hidden repository list
|
|
||||||
*
|
|
||||||
* @param array $hidden List of repositories to hide
|
|
||||||
*/
|
|
||||||
protected function setHidden($hidden)
|
|
||||||
{
|
|
||||||
$this->hidden = $hidden;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Commit;
|
|
||||||
|
|
||||||
class Author
|
|
||||||
{
|
|
||||||
protected $name;
|
|
||||||
protected $email;
|
|
||||||
|
|
||||||
public function __construct($name, $email)
|
|
||||||
{
|
|
||||||
$this->setName($name);
|
|
||||||
$this->setEmail($email);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmail()
|
|
||||||
{
|
|
||||||
return $this->email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setEmail($email)
|
|
||||||
{
|
|
||||||
$this->email = $email;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Commit;
|
|
||||||
|
|
||||||
class Commit
|
|
||||||
{
|
|
||||||
protected $hash;
|
|
||||||
protected $shortHash;
|
|
||||||
protected $treeHash;
|
|
||||||
protected $parentHash;
|
|
||||||
protected $author;
|
|
||||||
protected $date;
|
|
||||||
protected $commiter;
|
|
||||||
protected $commiterDate;
|
|
||||||
protected $message;
|
|
||||||
protected $diffs;
|
|
||||||
|
|
||||||
public function importData(array $data)
|
|
||||||
{
|
|
||||||
$this->setHash($data['hash']);
|
|
||||||
$this->setShortHash($data['short_hash']);
|
|
||||||
$this->setTreeHash($data['tree']);
|
|
||||||
$this->setParentHash($data['parent']);
|
|
||||||
|
|
||||||
$this->setAuthor(
|
|
||||||
new Author($data['author'], $data['author_email'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setDate(
|
|
||||||
new \DateTime('@' . $data['date'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setCommiter(
|
|
||||||
new Author($data['commiter'], $data['commiter_email'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setCommiterDate(
|
|
||||||
new \DateTime('@' . $data['commiter_date'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->setMessage($data['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHash()
|
|
||||||
{
|
|
||||||
return $this->hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHash($hash)
|
|
||||||
{
|
|
||||||
$this->hash = $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getShortHash()
|
|
||||||
{
|
|
||||||
return $this->shortHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setShortHash($shortHash)
|
|
||||||
{
|
|
||||||
$this->shortHash = $shortHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTreeHash()
|
|
||||||
{
|
|
||||||
return $this->treeHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTreeHash($treeHash)
|
|
||||||
{
|
|
||||||
$this->treeHash = $treeHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParentHash()
|
|
||||||
{
|
|
||||||
return $this->parentHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setParentHash($parentHash)
|
|
||||||
{
|
|
||||||
$this->parentHash = $parentHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAuthor()
|
|
||||||
{
|
|
||||||
return $this->author;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAuthor($author)
|
|
||||||
{
|
|
||||||
$this->author = $author;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDate()
|
|
||||||
{
|
|
||||||
return $this->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDate($date)
|
|
||||||
{
|
|
||||||
$this->date = $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCommiter()
|
|
||||||
{
|
|
||||||
return $this->commiter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCommiter($commiter)
|
|
||||||
{
|
|
||||||
$this->commiter = $commiter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCommiterDate()
|
|
||||||
{
|
|
||||||
return $this->commiterDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCommiterDate($commiterDate)
|
|
||||||
{
|
|
||||||
$this->commiterDate = $commiterDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMessage()
|
|
||||||
{
|
|
||||||
return $this->message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMessage($message)
|
|
||||||
{
|
|
||||||
$this->message = $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDiffs()
|
|
||||||
{
|
|
||||||
return $this->diffs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDiffs($diffs)
|
|
||||||
{
|
|
||||||
$this->diffs = $diffs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChangedFiles()
|
|
||||||
{
|
|
||||||
return sizeof($this->diffs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
use GitList\Component\Git\Client;
|
|
||||||
use GitList\Component\Git\Repository;
|
|
||||||
use GitList\Component\Git\ScopeAware;
|
|
||||||
|
|
||||||
class Blob extends ScopeAware
|
|
||||||
{
|
|
||||||
protected $mode;
|
|
||||||
protected $hash;
|
|
||||||
protected $name;
|
|
||||||
protected $size;
|
|
||||||
|
|
||||||
public function __construct($hash, Client $client, Repository $repository)
|
|
||||||
{
|
|
||||||
$this->setClient($client);
|
|
||||||
$this->setRepository($repository);
|
|
||||||
$this->setHash($hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function output()
|
|
||||||
{
|
|
||||||
$data = $this->getClient()->run($this->getRepository(), 'show ' . $this->getHash());
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMode()
|
|
||||||
{
|
|
||||||
return $this->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMode($mode)
|
|
||||||
{
|
|
||||||
$this->mode = $mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHash()
|
|
||||||
{
|
|
||||||
return $this->hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHash($hash)
|
|
||||||
{
|
|
||||||
$this->hash = $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSize()
|
|
||||||
{
|
|
||||||
return $this->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSize($size)
|
|
||||||
{
|
|
||||||
$this->size = $size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
use GitList\Component\Git\Model\DiffLine;
|
|
||||||
|
|
||||||
class Diff
|
|
||||||
{
|
|
||||||
protected $lines;
|
|
||||||
protected $index;
|
|
||||||
protected $old;
|
|
||||||
protected $new;
|
|
||||||
protected $file;
|
|
||||||
|
|
||||||
public function addLine($line, $oldNo, $newNo)
|
|
||||||
{
|
|
||||||
$this->lines[] = new DiffLine($line, $oldNo, $newNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLines()
|
|
||||||
{
|
|
||||||
return $this->lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIndex($index)
|
|
||||||
{
|
|
||||||
$this->index = $index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIndex()
|
|
||||||
{
|
|
||||||
return $this->index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setOld($old)
|
|
||||||
{
|
|
||||||
$this->old = $old;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOld()
|
|
||||||
{
|
|
||||||
return $this->old;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNew($new)
|
|
||||||
{
|
|
||||||
$this->new = $new;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNew()
|
|
||||||
{
|
|
||||||
return $this->new;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFile($file)
|
|
||||||
{
|
|
||||||
$this->file = $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFile()
|
|
||||||
{
|
|
||||||
return $this->file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
use GitList\Component\Git\Model\Line;
|
|
||||||
|
|
||||||
class DiffLine extends Line
|
|
||||||
{
|
|
||||||
protected $numNew;
|
|
||||||
protected $numOld;
|
|
||||||
|
|
||||||
public function __construct($data, $numOld, $numNew)
|
|
||||||
{
|
|
||||||
parent::__construct($data);
|
|
||||||
|
|
||||||
if (!empty($data)) {
|
|
||||||
switch ($data[0]) {
|
|
||||||
case '@':
|
|
||||||
$this->numOld = '...';
|
|
||||||
$this->numNew = '...';
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
$this->numOld = $numOld;
|
|
||||||
$this->numNew = '';
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
$this->numOld = '';
|
|
||||||
$this->numNew = $numNew;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$this->numOld = $numOld;
|
|
||||||
$this->numNew = $numNew;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->numOld = $numOld;
|
|
||||||
$this->numNew = $numNew;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNumOld()
|
|
||||||
{
|
|
||||||
return $this->numOld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNumOld($num)
|
|
||||||
{
|
|
||||||
$this->numOld = $num;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNumNew()
|
|
||||||
{
|
|
||||||
return $this->numNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNumNew($num)
|
|
||||||
{
|
|
||||||
$this->numNew = $num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
class Line
|
|
||||||
{
|
|
||||||
protected $line;
|
|
||||||
protected $type;
|
|
||||||
|
|
||||||
public function __construct($data)
|
|
||||||
{
|
|
||||||
if (!empty($data)) {
|
|
||||||
if ($data[0] == '@') {
|
|
||||||
$this->setType('chunk');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data[0] == '-') {
|
|
||||||
$this->setType('old');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data[0] == '+') {
|
|
||||||
$this->setType('new');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setLine($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLine()
|
|
||||||
{
|
|
||||||
return $this->line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setLine($line)
|
|
||||||
{
|
|
||||||
$this->line = $line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getType()
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setType($type)
|
|
||||||
{
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
class Symlink
|
|
||||||
{
|
|
||||||
protected $mode;
|
|
||||||
protected $name;
|
|
||||||
protected $path;
|
|
||||||
|
|
||||||
public function getMode()
|
|
||||||
{
|
|
||||||
return $this->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMode($mode)
|
|
||||||
{
|
|
||||||
$this->mode = $mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPath()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPath($path)
|
|
||||||
{
|
|
||||||
$this->path = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git\Model;
|
|
||||||
|
|
||||||
use GitList\Component\Git\Client;
|
|
||||||
use GitList\Component\Git\Repository;
|
|
||||||
use GitList\Component\Git\ScopeAware;
|
|
||||||
|
|
||||||
class Tree extends ScopeAware implements \RecursiveIterator
|
|
||||||
{
|
|
||||||
protected $mode;
|
|
||||||
protected $hash;
|
|
||||||
protected $name;
|
|
||||||
protected $data;
|
|
||||||
protected $position = 0;
|
|
||||||
|
|
||||||
public function __construct($hash, Client $client, Repository $repository)
|
|
||||||
{
|
|
||||||
$this->setClient($client);
|
|
||||||
$this->setRepository($repository);
|
|
||||||
$this->setHash($hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parse()
|
|
||||||
{
|
|
||||||
$data = $this->getClient()->run($this->getRepository(), 'ls-tree -l ' . $this->getHash());
|
|
||||||
$lines = explode("\n", $data);
|
|
||||||
$files = array();
|
|
||||||
$root = array();
|
|
||||||
|
|
||||||
foreach ($lines as $key => $line) {
|
|
||||||
if (empty($line)) {
|
|
||||||
unset($lines[$key]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files[] = preg_split("/[\s]+/", $line, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file[1] == 'commit') {
|
|
||||||
// submodule
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file[0] == '120000') {
|
|
||||||
$show = $this->getClient()->run($this->getRepository(), 'show ' . $file[2]);
|
|
||||||
$tree = new Symlink;
|
|
||||||
$tree->setMode($file[0]);
|
|
||||||
$tree->setName($file[4]);
|
|
||||||
$tree->setPath($show);
|
|
||||||
$root[] = $tree;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file[1] == 'blob') {
|
|
||||||
$blob = new Blob($file[2], $this->getClient(), $this->getRepository());
|
|
||||||
$blob->setMode($file[0]);
|
|
||||||
$blob->setName($file[4]);
|
|
||||||
$blob->setSize($file[3]);
|
|
||||||
$root[] = $blob;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tree = new Tree($file[2], $this->getClient(), $this->getRepository());
|
|
||||||
$tree->setMode($file[0]);
|
|
||||||
$tree->setName($file[4]);
|
|
||||||
$root[] = $tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data = $root;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function output()
|
|
||||||
{
|
|
||||||
$files = $folders = array();
|
|
||||||
|
|
||||||
foreach ($this as $node) {
|
|
||||||
if ($node instanceof Blob) {
|
|
||||||
$file['type'] = 'blob';
|
|
||||||
$file['name'] = $node->getName();
|
|
||||||
$file['size'] = $node->getSize();
|
|
||||||
$file['mode'] = $node->getMode();
|
|
||||||
$file['hash'] = $node->getHash();
|
|
||||||
$files[] = $file;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node instanceof Tree) {
|
|
||||||
$folder['type'] = 'folder';
|
|
||||||
$folder['name'] = $node->getName();
|
|
||||||
$folder['size'] = '';
|
|
||||||
$folder['mode'] = $node->getMode();
|
|
||||||
$folder['hash'] = $node->getHash();
|
|
||||||
$folders[] = $folder;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node instanceof Symlink) {
|
|
||||||
$folder['type'] = 'symlink';
|
|
||||||
$folder['name'] = $node->getName();
|
|
||||||
$folder['size'] = '';
|
|
||||||
$folder['mode'] = $node->getMode();
|
|
||||||
$folder['hash'] = '';
|
|
||||||
$folder['path'] = $node->getPath();
|
|
||||||
$folders[] = $folder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Little hack to make folders appear before files
|
|
||||||
$files = array_merge($folders, $files);
|
|
||||||
|
|
||||||
return $files;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
return isset($this->data[$this->position]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasChildren()
|
|
||||||
{
|
|
||||||
return is_array($this->data[$this->position]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
$this->position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
return $this->data[$this->position];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChildren()
|
|
||||||
{
|
|
||||||
return $this->data[$this->position];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
$this->position = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMode()
|
|
||||||
{
|
|
||||||
return $this->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMode($mode)
|
|
||||||
{
|
|
||||||
$this->mode = $mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHash()
|
|
||||||
{
|
|
||||||
return $this->hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHash($hash)
|
|
||||||
{
|
|
||||||
$this->hash = $hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,615 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git;
|
|
||||||
|
|
||||||
use GitList\Component\Git\Commit\Commit;
|
|
||||||
use GitList\Component\Git\Model\Tree;
|
|
||||||
use GitList\Component\Git\Model\Blob;
|
|
||||||
use GitList\Component\Git\Model\Diff;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
class Repository
|
|
||||||
{
|
|
||||||
protected $path;
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
public function __construct($path, Client $client)
|
|
||||||
{
|
|
||||||
$this->setPath($path);
|
|
||||||
$this->setClient($client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setClient(Client $client)
|
|
||||||
{
|
|
||||||
$this->client = $client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClient()
|
|
||||||
{
|
|
||||||
return $this->client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
mkdir($this->getPath());
|
|
||||||
$this->getClient()->run($this, 'init');
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConfig($key)
|
|
||||||
{
|
|
||||||
$key = $this->getClient()->run($this, 'config ' . $key);
|
|
||||||
|
|
||||||
return trim($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setConfig($key, $value)
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "config $key \"$value\"");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add untracked files
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param mixed $files Files to be added to the repository
|
|
||||||
*/
|
|
||||||
public function add($files = '.')
|
|
||||||
{
|
|
||||||
if (is_array($files)) {
|
|
||||||
$files = implode(' ', $files);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getClient()->run($this, "add $files");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add all untracked files
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public function addAll()
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "add -A");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit changes to the repository
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param string $message Description of the changes made
|
|
||||||
*/
|
|
||||||
public function commit($message)
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "commit -m \"$message\"");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checkout a branch
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param string $branch Branch to be checked out
|
|
||||||
*/
|
|
||||||
public function checkout($branch)
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "checkout $branch");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pull repository changes
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public function pull()
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "pull");
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update remote references
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param string $repository Repository to be pushed
|
|
||||||
* @param string $refspec Refspec for the push
|
|
||||||
*/
|
|
||||||
public function push($repository = null, $refspec = null)
|
|
||||||
{
|
|
||||||
$command = "push";
|
|
||||||
|
|
||||||
if ($repository) {
|
|
||||||
$command .= " $repository";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($refspec) {
|
|
||||||
$command .= " $refspec";
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getClient()->run($this, $command);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a list of the repository branches
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return array List of branches
|
|
||||||
*/
|
|
||||||
public function getBranches()
|
|
||||||
{
|
|
||||||
$branches = $this->getClient()->run($this, "branch");
|
|
||||||
$branches = explode("\n", $branches);
|
|
||||||
$branches = array_filter(preg_replace('/[\*\s]/', '', $branches));
|
|
||||||
|
|
||||||
return $branches;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the current repository branch
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return string Current repository branch
|
|
||||||
*/
|
|
||||||
public function getCurrentBranch()
|
|
||||||
{
|
|
||||||
$branches = $this->getClient()->run($this, "branch");
|
|
||||||
$branches = explode("\n", $branches);
|
|
||||||
|
|
||||||
foreach ($branches as $branch) {
|
|
||||||
if ($branch[0] == '*') {
|
|
||||||
return substr($branch, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a specified branch exists
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param string $branch Branch to be checked
|
|
||||||
* @return boolean True if the branch exists
|
|
||||||
*/
|
|
||||||
public function hasBranch($branch)
|
|
||||||
{
|
|
||||||
$branches = $this->getBranches();
|
|
||||||
$status = in_array($branch, $branches);
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new repository branch
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param string $branch Branch name
|
|
||||||
*/
|
|
||||||
public function createBranch($branch)
|
|
||||||
{
|
|
||||||
$this->getClient()->run($this, "branch $branch");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a list of the repository tags
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return array List of tags
|
|
||||||
*/
|
|
||||||
public function getTags()
|
|
||||||
{
|
|
||||||
$tags = $this->getClient()->run($this, "tag");
|
|
||||||
$tags = explode("\n", $tags);
|
|
||||||
|
|
||||||
if (empty($tags[0])) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the amount of commits on the repository
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return integer Total number of commits
|
|
||||||
*/
|
|
||||||
public function getTotalCommits($file = null)
|
|
||||||
{
|
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
||||||
$command = "rev-list --count --all $file";
|
|
||||||
} else {
|
|
||||||
$command = "rev-list --all $file | wc -l";
|
|
||||||
}
|
|
||||||
|
|
||||||
$commits = $this->getClient()->run($this, $command);
|
|
||||||
|
|
||||||
return $commits;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the repository commit log
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return array Commit log
|
|
||||||
*/
|
|
||||||
public function getCommits($file = null, $page = 0)
|
|
||||||
{
|
|
||||||
$page = 15 * $page;
|
|
||||||
$pager = "--skip=$page --max-count=15";
|
|
||||||
$command = 'log ' . $pager . ' --pretty=format:"\"%h\": {\"hash\": \"%H\", \"short_hash\": \"%h\", \"tree\": \"%T\", \"parent\": \"%P\", \"author\": \"%an\", \"author_email\": \"%ae\", \"date\": \"%at\", \"commiter\": \"%cn\", \"commiter_email\": \"%ce\", \"commiter_date\": \"%ct\", \"message\": \"%f\"}"';
|
|
||||||
|
|
||||||
if ($file) {
|
|
||||||
$command .= " $file";
|
|
||||||
}
|
|
||||||
|
|
||||||
$logs = $this->getClient()->run($this, $command);
|
|
||||||
|
|
||||||
if (empty($logs)) {
|
|
||||||
throw new \RuntimeException('No commit log available');
|
|
||||||
}
|
|
||||||
|
|
||||||
$logs = str_replace("\n", ',', $logs);
|
|
||||||
$logs = json_decode("{ $logs }", true);
|
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
$log['message'] = str_replace('-', ' ', $log['message']);
|
|
||||||
$commit = new Commit;
|
|
||||||
$commit->importData($log);
|
|
||||||
$commits[] = $commit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $commits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRelatedCommits($hash)
|
|
||||||
{
|
|
||||||
$logs = $this->getClient()->run($this, 'log --pretty=format:"\"%h\": {\"hash\": \"%H\", \"short_hash\": \"%h\", \"tree\": \"%T\", \"parent\": \"%P\", \"author\": \"%an\", \"author_email\": \"%ae\", \"date\": \"%at\", \"commiter\": \"%cn\", \"commiter_email\": \"%ce\", \"commiter_date\": \"%ct\", \"message\": \"%f\"}"');
|
|
||||||
|
|
||||||
if (empty($logs)) {
|
|
||||||
throw new \RuntimeException('No commit log available');
|
|
||||||
}
|
|
||||||
|
|
||||||
$logs = str_replace("\n", ',', $logs);
|
|
||||||
$logs = json_decode("{ $logs }", true);
|
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
$log['message'] = str_replace('-', ' ', $log['message']);
|
|
||||||
$logTree = $this->getClient()->run($this, 'diff-tree -t -r ' . $log['hash']);
|
|
||||||
$lines = explode("\n", $logTree);
|
|
||||||
array_shift($lines);
|
|
||||||
$files = array();
|
|
||||||
|
|
||||||
foreach ($lines as $key => $line) {
|
|
||||||
if (empty($line)) {
|
|
||||||
unset($lines[$key]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files[] = preg_split("/[\s]+/", $line);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now let's find the commits who have our hash within them
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file[1] == 'commit') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file[3] == $hash) {
|
|
||||||
$commit = new Commit;
|
|
||||||
$commit->importData($log);
|
|
||||||
$commits[] = $commit;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $commits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCommit($commitHash)
|
|
||||||
{
|
|
||||||
$logs = $this->getClient()->run($this, 'show --pretty=format:"{\"hash\": \"%H\", \"short_hash\": \"%h\", \"tree\": \"%T\", \"parent\": \"%P\", \"author\": \"%an\", \"author_email\": \"%ae\", \"date\": \"%at\", \"commiter\": \"%cn\", \"commiter_email\": \"%ce\", \"commiter_date\": \"%ct\", \"message\": \"%f\"}" ' . $commitHash);
|
|
||||||
|
|
||||||
if (empty($logs)) {
|
|
||||||
throw new \RuntimeException('No commit log available');
|
|
||||||
}
|
|
||||||
|
|
||||||
$logs = explode("\n", $logs);
|
|
||||||
|
|
||||||
// Read commit metadata
|
|
||||||
$data = json_decode($logs[0], true);
|
|
||||||
$data['message'] = str_replace('-', ' ', $data['message']);
|
|
||||||
$commit = new Commit;
|
|
||||||
$commit->importData($data);
|
|
||||||
unset($logs[0]);
|
|
||||||
|
|
||||||
if (empty($logs[1])) {
|
|
||||||
$logs = explode("\n", $this->getClient()->run($this, 'diff ' . $commitHash . '~1..' . $commitHash));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read diff logs
|
|
||||||
$lineNumOld = 0;
|
|
||||||
$lineNumNew = 0;
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
if ('diff' === substr($log, 0, 4)) {
|
|
||||||
if (isset($diff)) {
|
|
||||||
$diffs[] = $diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff = new Diff;
|
|
||||||
preg_match('/^diff --[\S]+ (a\/)?([\S]+)( b\/)?/', $log, $name);
|
|
||||||
$diff->setFile($name[2]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('index' === substr($log, 0, 5)) {
|
|
||||||
$diff->setIndex($log);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('---' === substr($log, 0, 3)) {
|
|
||||||
$diff->setOld($log);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('+++' === substr($log, 0, 3)) {
|
|
||||||
$diff->setNew($log);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle binary files properly.
|
|
||||||
if ('Binary' === substr($log, 0, 6)) {
|
|
||||||
$m = array();
|
|
||||||
if (preg_match('/Binary files (.+) and (.+) differ/', $log, $m)) {
|
|
||||||
$diff->setOld($m[1]);
|
|
||||||
$diff->setNew(" {$m[2]}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($log)) {
|
|
||||||
switch ($log[0]) {
|
|
||||||
case "@":
|
|
||||||
// Set the line numbers
|
|
||||||
preg_match('/@@ -([0-9]+)/', $log, $matches);
|
|
||||||
$lineNumOld = $matches[1] - 1;
|
|
||||||
$lineNumNew = $matches[1] - 1;
|
|
||||||
break;
|
|
||||||
case "-":
|
|
||||||
$lineNumOld++;
|
|
||||||
break;
|
|
||||||
case "+":
|
|
||||||
$lineNumNew++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$lineNumOld++;
|
|
||||||
$lineNumNew++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$lineNumOld++;
|
|
||||||
$lineNumNew++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff->addLine($log, $lineNumOld, $lineNumNew);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($diff)) {
|
|
||||||
$diffs[] = $diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
$commit->setDiffs($diffs);
|
|
||||||
|
|
||||||
return $commit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAuthorStatistics()
|
|
||||||
{
|
|
||||||
$logs = $this->getClient()->run($this, 'log --pretty=format:"%an||%ae" ' . $this->getHead());
|
|
||||||
|
|
||||||
if (empty($logs)) {
|
|
||||||
throw new \RuntimeException('No statistics available');
|
|
||||||
}
|
|
||||||
|
|
||||||
$logs = explode("\n", $logs);
|
|
||||||
$logs = array_count_values($logs);
|
|
||||||
arsort($logs);
|
|
||||||
|
|
||||||
foreach ($logs as $user => $count) {
|
|
||||||
$user = explode('||', $user);
|
|
||||||
$data[] = array('name' => $user[0], 'email' => $user[1], 'commits' => $count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current HEAD.
|
|
||||||
*
|
|
||||||
* @return string the name of the HEAD branch.
|
|
||||||
*/
|
|
||||||
public function getHead()
|
|
||||||
{
|
|
||||||
if (file_exists($this->getPath() . '/.git/HEAD')) {
|
|
||||||
$file = @file_get_contents($this->getPath() . '/.git/HEAD');
|
|
||||||
} elseif (file_exists($this->getPath() . '/HEAD')) {
|
|
||||||
$file = @file_get_contents($this->getPath() . '/HEAD');
|
|
||||||
} else {
|
|
||||||
return 'master';
|
|
||||||
}
|
|
||||||
// Find first existing branch
|
|
||||||
foreach (explode("\n", $file) as $line) {
|
|
||||||
$m = array();
|
|
||||||
if (preg_match('#ref:\srefs/heads/(.+)#', $line, $m)) {
|
|
||||||
if ($this->hasBranch($m[1])) {
|
|
||||||
return $m[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to something sane if in a detached HEAD state.
|
|
||||||
$branches = $this->getBranches();
|
|
||||||
if (!empty($branches)) {
|
|
||||||
return current($branches);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'master';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getStatistics($branch)
|
|
||||||
{
|
|
||||||
// Calculate amount of files, extensions and file size
|
|
||||||
$logs = $this->getClient()->run($this, 'ls-tree -r -l ' . $branch);
|
|
||||||
$lines = explode("\n", $logs);
|
|
||||||
$files = array();
|
|
||||||
$data['extensions'] = array();
|
|
||||||
$data['size'] = 0;
|
|
||||||
$data['files'] = 0;
|
|
||||||
|
|
||||||
foreach ($lines as $key => $line) {
|
|
||||||
if (empty($line)) {
|
|
||||||
unset($lines[$key]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files[] = preg_split("/[\s]+/", $line);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file[1] == 'blob') {
|
|
||||||
$data['files']++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_numeric($file[3])) {
|
|
||||||
$data['size'] += $file[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($pos = strrpos($file[4], '.')) !== FALSE) {
|
|
||||||
$data['extensions'][] = substr($file[4], $pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['extensions'] = array_count_values($data['extensions']);
|
|
||||||
arsort($data['extensions']);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the tree hash for a given branch or tree reference
|
|
||||||
*
|
|
||||||
* @param string $branch
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getBranchTree($branch)
|
|
||||||
{
|
|
||||||
$hash = $this->getClient()->run($this, "log --pretty=\"%T\" --max-count=1 $branch");
|
|
||||||
$hash = trim($hash, "\r\n ");
|
|
||||||
|
|
||||||
return $hash ? : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TAR or ZIP archive of a git tree
|
|
||||||
*
|
|
||||||
* @param string $tree Tree-ish reference
|
|
||||||
* @param string $output Output File name
|
|
||||||
* @param string $format Archive format
|
|
||||||
*/
|
|
||||||
public function createArchive($tree, $output, $format = 'zip')
|
|
||||||
{
|
|
||||||
$fs = new Filesystem;
|
|
||||||
$fs->mkdir(dirname($output));
|
|
||||||
$this->getClient()->run($this, "archive --format=$format --output=$output $tree");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Tree for the provided folder
|
|
||||||
*
|
|
||||||
* @param string $tree Folder that will be parsed
|
|
||||||
* @return Tree Instance of Tree for the provided folder
|
|
||||||
*/
|
|
||||||
public function getTree($tree)
|
|
||||||
{
|
|
||||||
$tree = new Tree($tree, $this->getClient(), $this);
|
|
||||||
$tree->parse();
|
|
||||||
|
|
||||||
return $tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Blob for the provided file
|
|
||||||
*
|
|
||||||
* @param string $blob File that will be parsed
|
|
||||||
* @return Blob Instance of Blob for the provided file
|
|
||||||
*/
|
|
||||||
public function getBlob($blob)
|
|
||||||
{
|
|
||||||
return new Blob($blob, $this->getClient(), $this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blames the provided file and parses the output
|
|
||||||
*
|
|
||||||
* @param string $file File that will be blamed
|
|
||||||
* @return array Commits hashes containing the lines
|
|
||||||
*/
|
|
||||||
public function getBlame($file)
|
|
||||||
{
|
|
||||||
$blame = array();
|
|
||||||
$logs = $this->getClient()->run($this, "blame -s $file");
|
|
||||||
$logs = explode("\n", $logs);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
$previous_commit = '';
|
|
||||||
foreach ($logs as $log) {
|
|
||||||
if ($log == '') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
preg_match_all("/([a-zA-Z0-9^]{8})\s+.*?([0-9]+)\)(.+)/", $log, $match);
|
|
||||||
|
|
||||||
$current_commit = $match[1][0];
|
|
||||||
$current_commit = str_replace('^', '', $current_commit);
|
|
||||||
if ($current_commit != $previous_commit) {
|
|
||||||
++$i;
|
|
||||||
$blame[$i] = array('line' => '', 'commit' => $current_commit);
|
|
||||||
}
|
|
||||||
|
|
||||||
$blame[$i]['line'] .= PHP_EOL . $match[3][0];
|
|
||||||
$previous_commit = $current_commit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $blame;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current Repository path
|
|
||||||
*
|
|
||||||
* @return string Path where the repository is located
|
|
||||||
*/
|
|
||||||
public function getPath()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current Repository path
|
|
||||||
*
|
|
||||||
* @param string $path Path where the repository is located
|
|
||||||
*/
|
|
||||||
public function setPath($path)
|
|
||||||
{
|
|
||||||
$this->path = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace GitList\Component\Git;
|
|
||||||
|
|
||||||
class ScopeAware
|
|
||||||
{
|
|
||||||
protected $client;
|
|
||||||
protected $repository;
|
|
||||||
|
|
||||||
public function setClient(Client $client)
|
|
||||||
{
|
|
||||||
$this->client = $client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClient()
|
|
||||||
{
|
|
||||||
return $this->client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRepository()
|
|
||||||
{
|
|
||||||
return $this->repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setRepository($repository)
|
|
||||||
{
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@ class CommitController implements ControllerProviderInterface
|
|||||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||||
$type = $file ? "$branch -- $file" : $branch;
|
$type = $file ? "$branch -- $file" : $branch;
|
||||||
$pager = $app['util.view']->getPager($app['request']->get('page'), $repository->getTotalCommits($type));
|
$pager = $app['util.view']->getPager($app['request']->get('page'), $repository->getTotalCommits($type));
|
||||||
$commits = $repository->getCommits($type, $pager['current']);
|
$commits = $repository->getPaginatedCommits($type, $pager['current']);
|
||||||
|
|
||||||
foreach ($commits as $commit) {
|
foreach ($commits as $commit) {
|
||||||
$date = $commit->getDate();
|
$date = $commit->getDate();
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class MainController implements ControllerProviderInterface
|
|||||||
|
|
||||||
$route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
|
$route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
|
||||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||||
$commits = $repository->getCommits($branch);
|
$commits = $repository->getPaginatedCommits($branch);
|
||||||
|
|
||||||
$html = $app['twig']->render('rss.twig', array(
|
$html = $app['twig']->render('rss.twig', array(
|
||||||
'repo' => $repo,
|
'repo' => $repo,
|
||||||
|
|||||||
44
src/GitList/Git/Client.php
Normal file
44
src/GitList/Git/Client.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace GitList\Git;
|
||||||
|
|
||||||
|
use Gitter\Client as BaseClient;
|
||||||
|
|
||||||
|
class Client extends BaseClient
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new repository on the specified path
|
||||||
|
*
|
||||||
|
* @param string $path Path where the new repository will be created
|
||||||
|
* @return Repository Instance of Repository
|
||||||
|
*/
|
||||||
|
public function createRepository($path, $bare = null)
|
||||||
|
{
|
||||||
|
if (file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
|
||||||
|
throw new \RuntimeException('A GIT repository already exists at ' . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$repository = new Repository($path, $this);
|
||||||
|
|
||||||
|
return $repository->create($bare);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a repository at the specified path
|
||||||
|
*
|
||||||
|
* @param string $path Path where the repository is located
|
||||||
|
* @return Repository Instance of Repository
|
||||||
|
*/
|
||||||
|
public function getRepository($path)
|
||||||
|
{
|
||||||
|
if (!file_exists($path) || !file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
|
||||||
|
throw new \RuntimeException('There is no GIT repository at ' . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($path, $this->getHidden())) {
|
||||||
|
throw new \RuntimeException('You don\'t have access to this repository');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Repository($path, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
src/GitList/Git/Repository.php
Normal file
110
src/GitList/Git/Repository.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace GitList\Git;
|
||||||
|
|
||||||
|
use Gitter\Repository as BaseRepository;
|
||||||
|
use Gitter\Model\Commit\Commit;
|
||||||
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
|
class Repository extends BaseRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show the repository commit log with pagination
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array Commit log
|
||||||
|
*/
|
||||||
|
public function getPaginatedCommits($file = null, $page = 0)
|
||||||
|
{
|
||||||
|
$page = 15 * $page;
|
||||||
|
$pager = "--skip=$page --max-count=15";
|
||||||
|
$command = "log $pager --pretty=format:'<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parent>%P</parent><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message></item>'";
|
||||||
|
|
||||||
|
if ($file) {
|
||||||
|
$command .= " $file";
|
||||||
|
}
|
||||||
|
|
||||||
|
$logs = $this->getPrettyFormat($command);
|
||||||
|
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$commit = new Commit;
|
||||||
|
$commit->importData($log);
|
||||||
|
$commits[] = $commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $commits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthorStatistics()
|
||||||
|
{
|
||||||
|
$logs = $this->getClient()->run($this, 'log --pretty=format:"%an||%ae" ' . $this->getHead());
|
||||||
|
|
||||||
|
if (empty($logs)) {
|
||||||
|
throw new \RuntimeException('No statistics available');
|
||||||
|
}
|
||||||
|
|
||||||
|
$logs = explode("\n", $logs);
|
||||||
|
$logs = array_count_values($logs);
|
||||||
|
arsort($logs);
|
||||||
|
|
||||||
|
foreach ($logs as $user => $count) {
|
||||||
|
$user = explode('||', $user);
|
||||||
|
$data[] = array('name' => $user[0], 'email' => $user[1], 'commits' => $count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatistics($branch)
|
||||||
|
{
|
||||||
|
// Calculate amount of files, extensions and file size
|
||||||
|
$logs = $this->getClient()->run($this, 'ls-tree -r -l ' . $branch);
|
||||||
|
$lines = explode("\n", $logs);
|
||||||
|
$files = array();
|
||||||
|
$data['extensions'] = array();
|
||||||
|
$data['size'] = 0;
|
||||||
|
$data['files'] = 0;
|
||||||
|
|
||||||
|
foreach ($lines as $key => $line) {
|
||||||
|
if (empty($line)) {
|
||||||
|
unset($lines[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$files[] = preg_split("/[\s]+/", $line);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file[1] == 'blob') {
|
||||||
|
$data['files']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($file[3])) {
|
||||||
|
$data['size'] += $file[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($pos = strrpos($file[4], '.')) !== FALSE) {
|
||||||
|
$data['extensions'][] = substr($file[4], $pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['extensions'] = array_count_values($data['extensions']);
|
||||||
|
arsort($data['extensions']);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TAR or ZIP archive of a git tree
|
||||||
|
*
|
||||||
|
* @param string $tree Tree-ish reference
|
||||||
|
* @param string $output Output File name
|
||||||
|
* @param string $format Archive format
|
||||||
|
*/
|
||||||
|
public function createArchive($tree, $output, $format = 'zip')
|
||||||
|
{
|
||||||
|
$fs = new Filesystem;
|
||||||
|
$fs->mkdir(dirname($output));
|
||||||
|
$this->getClient()->run($this, "archive --format=$format --output=$output $tree");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace GitList\Provider;
|
namespace GitList\Provider;
|
||||||
|
|
||||||
use GitList\Component\Git\Client;
|
use GitList\Git\Client;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
|
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use GitList\Component\Git\Client;
|
|
||||||
use GitList\Component\Git\Repository;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
class ClientTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
protected static $tmpdir;
|
|
||||||
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
if (getenv('TMP')) {
|
|
||||||
self::$tmpdir = getenv('TMP');
|
|
||||||
} elseif (getenv('TMPDIR')) {
|
|
||||||
self::$tmpdir = getenv('TMPDIR');
|
|
||||||
} else {
|
|
||||||
self::$tmpdir = '/tmp';
|
|
||||||
}
|
|
||||||
|
|
||||||
self::$tmpdir .= '/gitlist_' . md5(time() . mt_rand());
|
|
||||||
|
|
||||||
$fs = new Filesystem();
|
|
||||||
$fs->mkdir(self::$tmpdir);
|
|
||||||
|
|
||||||
if (!is_writable(self::$tmpdir)) {
|
|
||||||
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
if (!is_writable(self::$tmpdir)) {
|
|
||||||
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$options['path'] = getenv('GIT_CLIENT') ?: '/usr/bin/git';
|
|
||||||
$options['hidden'] = array(self::$tmpdir . '/hiddenrepo');
|
|
||||||
$this->client = new Client($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsNotFindingRepositories()
|
|
||||||
{
|
|
||||||
$this->client->getRepositories(self::$tmpdir . '/testrepo');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsNotAbleToGetUnexistingRepository()
|
|
||||||
{
|
|
||||||
$this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsNotAbleToGetUnexistingRepositories()
|
|
||||||
{
|
|
||||||
$this->client->getRepositories(self::$tmpdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsCreatingRepository()
|
|
||||||
{
|
|
||||||
$repository = $this->client->createRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$this->assertRegExp("/nothing to commit/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsNotAbleToCreateRepositoryDueToExistingOne()
|
|
||||||
{
|
|
||||||
$this->client->createRepository(self::$tmpdir . '/testrepo');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsListingRepositories()
|
|
||||||
{
|
|
||||||
$this->client->createRepository(self::$tmpdir . '/anothertestrepo');
|
|
||||||
$this->client->createRepository(self::$tmpdir . '/bigbadrepo');
|
|
||||||
$repositories = $this->client->getRepositories(self::$tmpdir);
|
|
||||||
|
|
||||||
$this->assertEquals($repositories[0]['name'], 'anothertestrepo');
|
|
||||||
$this->assertEquals($repositories[1]['name'], 'bigbadrepo');
|
|
||||||
$this->assertEquals($repositories[2]['name'], 'testrepo');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsNotListingHiddenRepositories()
|
|
||||||
{
|
|
||||||
$this->client->createRepository(self::$tmpdir . '/hiddenrepo');
|
|
||||||
$repositories = $this->client->getRepositories(self::$tmpdir);
|
|
||||||
|
|
||||||
$this->assertEquals($repositories[0]['name'], 'anothertestrepo');
|
|
||||||
$this->assertEquals($repositories[1]['name'], 'bigbadrepo');
|
|
||||||
$this->assertEquals($repositories[2]['name'], 'testrepo');
|
|
||||||
$this->assertFalse(isset($repositories[3]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsNotOpeningHiddenRepositories()
|
|
||||||
{
|
|
||||||
$this->client->getRepository(self::$tmpdir . '/hiddenrepo');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException RuntimeException
|
|
||||||
*/
|
|
||||||
public function testIsCatchingGitCommandErrors()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$repository->getClient()->run($repository, 'wrong');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
|
||||||
{
|
|
||||||
$fs = new Filesystem();
|
|
||||||
|
|
||||||
try {
|
|
||||||
//$fs->remove(self::$tmpdir);
|
|
||||||
} catch (IOException $e) {
|
|
||||||
// Ignore, file is not closed yet
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Silex\WebTestCase;
|
use Silex\WebTestCase;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use Gitter\Client;
|
||||||
use GitList\Component\Git\Client;
|
|
||||||
|
|
||||||
class InterfaceTest extends WebTestCase
|
class InterfaceTest extends WebTestCase
|
||||||
{
|
{
|
||||||
@@ -204,11 +201,6 @@ class InterfaceTest extends WebTestCase
|
|||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
$fs = new Filesystem();
|
$fs = new Filesystem();
|
||||||
|
$fs->remove(self::$tmpdir);
|
||||||
try {
|
|
||||||
$fs->remove(self::$tmpdir);
|
|
||||||
} catch (IOException $e) {
|
|
||||||
// Ignore, file is not closed yet
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,401 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use GitList\Component\Git\Client;
|
|
||||||
use GitList\Component\Git\Repository;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
class RepositoryTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
protected static $tmpdir;
|
|
||||||
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
if (getenv('TMP')) {
|
|
||||||
self::$tmpdir = getenv('TMP');
|
|
||||||
} elseif (getenv('TMPDIR')) {
|
|
||||||
self::$tmpdir = getenv('TMPDIR');
|
|
||||||
} else {
|
|
||||||
self::$tmpdir = '/tmp';
|
|
||||||
}
|
|
||||||
|
|
||||||
self::$tmpdir .= '/gitlist_' . md5(time() . mt_rand());
|
|
||||||
|
|
||||||
$fs = new Filesystem();
|
|
||||||
$fs->mkdir(self::$tmpdir);
|
|
||||||
|
|
||||||
if (!is_writable(self::$tmpdir)) {
|
|
||||||
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
if (!is_writable(self::$tmpdir)) {
|
|
||||||
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$options['path'] = getenv('GIT_CLIENT') ?: '/usr/bin/git';
|
|
||||||
$options['hidden'] = array();
|
|
||||||
$this->client = new Client($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsCreatingRepositoryFixtures()
|
|
||||||
{
|
|
||||||
$a = $this->client->createRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$b = $this->client->createRepository(self::$tmpdir . '/anothertestrepo');
|
|
||||||
$c = $this->client->createRepository(self::$tmpdir . '/bigbadrepo');
|
|
||||||
$this->assertRegExp("/nothing to commit/", $a->getClient()->run($a, 'status'));
|
|
||||||
$this->assertRegExp("/nothing to commit/", $b->getClient()->run($b, 'status'));
|
|
||||||
$this->assertRegExp("/nothing to commit/", $c->getClient()->run($c, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsConfiguratingRepository()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$repository->setConfig('user.name', 'Luke Skywalker');
|
|
||||||
$repository->setConfig('user.email', 'luke@rebel.org');
|
|
||||||
|
|
||||||
$this->assertEquals($repository->getConfig('user.name'), 'Luke Skywalker');
|
|
||||||
$this->assertEquals($repository->getConfig('user.email'), 'luke@rebel.org');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsAdding()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
$repository->add('test_file.txt');
|
|
||||||
$this->assertRegExp("/new file: test_file.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsAdding
|
|
||||||
*/
|
|
||||||
public function testIsAddingDot()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file1.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file2.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file3.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
|
|
||||||
$repository->add();
|
|
||||||
|
|
||||||
$this->assertRegExp("/new file: test_file1.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file2.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file3.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsAddingDot
|
|
||||||
*/
|
|
||||||
public function testIsAddingAll()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file4.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file5.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file6.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
|
|
||||||
$repository->addAll();
|
|
||||||
|
|
||||||
$this->assertRegExp("/new file: test_file4.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file5.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file6.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsAddingAll
|
|
||||||
*/
|
|
||||||
public function testIsAddingArrayOfFiles()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file7.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file8.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/test_file9.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
|
|
||||||
|
|
||||||
$repository->add(array('test_file7.txt', 'test_file8.txt', 'test_file9.txt'));
|
|
||||||
|
|
||||||
$this->assertRegExp("/new file: test_file7.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file8.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
$this->assertRegExp("/new file: test_file9.txt/", $repository->getClient()->run($repository, 'status'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsAddingArrayOfFiles
|
|
||||||
*/
|
|
||||||
public function testIsCommiting()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$repository->commit("The truth unveiled");
|
|
||||||
$this->assertRegExp("/The truth unveiled/", $repository->getClient()->run($repository, 'log'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsCreatingBranches()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$repository->createBranch('issue12');
|
|
||||||
$repository->createBranch('issue42');
|
|
||||||
$branches = $repository->getBranches();
|
|
||||||
$this->assertContains('issue12', $branches);
|
|
||||||
$this->assertContains('issue42', $branches);
|
|
||||||
$this->assertContains('master', $branches);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingCurrentBranch()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$branch = $repository->getCurrentBranch();
|
|
||||||
$this->assertTrue($branch === 'master');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsCommiting
|
|
||||||
*/
|
|
||||||
public function testIsGettingCommits()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$commits = $repository->getCommits();
|
|
||||||
|
|
||||||
foreach ($commits as $commit) {
|
|
||||||
$this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit);
|
|
||||||
$this->assertTrue($commit->getMessage() === 'The truth unveiled');
|
|
||||||
$this->assertInstanceOf('GitList\Component\Git\Commit\Author', $commit->getAuthor());
|
|
||||||
$this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker');
|
|
||||||
$this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org');
|
|
||||||
$this->assertEquals($commit->getCommiter()->getName(), 'Luke Skywalker');
|
|
||||||
$this->assertEquals($commit->getCommiter()->getEmail(), 'luke@rebel.org');
|
|
||||||
$this->assertEquals($commit->getParentHash(), '');
|
|
||||||
$this->assertInstanceOf('DateTime', $commit->getDate());
|
|
||||||
$this->assertInstanceOf('DateTime', $commit->getCommiterDate());
|
|
||||||
$this->assertRegExp('/[a-f0-9]+/', $commit->getHash());
|
|
||||||
$this->assertRegExp('/[a-f0-9]+/', $commit->getShortHash());
|
|
||||||
$this->assertRegExp('/[a-f0-9]+/', $commit->getTreeHash());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @depends testIsGettingCommits
|
|
||||||
*/
|
|
||||||
public function testIsGettingCommitsFromSpecificFile()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$commits = $repository->getCommits('test_file4.txt');
|
|
||||||
|
|
||||||
foreach ($commits as $commit) {
|
|
||||||
$this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit);
|
|
||||||
$this->assertTrue($commit->getMessage() === 'The truth unveiled');
|
|
||||||
$this->assertInstanceOf('GitList\Component\Git\Commit\Author', $commit->getAuthor());
|
|
||||||
$this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker');
|
|
||||||
$this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingTree()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$files = $repository->getTree('master');
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$this->assertInstanceOf('GitList\Component\Git\Model\Blob', $file);
|
|
||||||
$this->assertRegExp('/test_file[0-9]*.txt/', $file->getName());
|
|
||||||
$this->assertEquals($file->getSize(), '55');
|
|
||||||
$this->assertEquals($file->getMode(), '100644');
|
|
||||||
$this->assertRegExp('/[a-f0-9]+/', $file->getHash());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingTreeOutput()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$files = $repository->getTree('master')->output();
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$this->assertEquals('blob', $file['type']);
|
|
||||||
$this->assertRegExp('/test_file[0-9]*.txt/', $file['name']);
|
|
||||||
$this->assertEquals($file['size'], '55');
|
|
||||||
$this->assertEquals($file['mode'], '100644');
|
|
||||||
$this->assertRegExp('/[a-f0-9]+/', $file['hash']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingTreesWithinTree()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
|
|
||||||
// Creating folders
|
|
||||||
mkdir(self::$tmpdir . '/testrepo/MyFolder');
|
|
||||||
mkdir(self::$tmpdir . '/testrepo/MyTest');
|
|
||||||
mkdir(self::$tmpdir . '/testrepo/MyFolder/Tests');
|
|
||||||
|
|
||||||
// Populating created folders
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit amet');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/skywalker.php', 'Lorem ipsum dolor sit amet');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyTest/fortytwo.php', 'Lorem ipsum dolor sit amet');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/web.php', 'Lorem ipsum dolor sit amet');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/cli.php', 'Lorem ipsum dolor sit amet');
|
|
||||||
|
|
||||||
// Adding and commiting
|
|
||||||
$repository->addAll();
|
|
||||||
$repository->commit("Creating folders for testIsGettingTreesWithinTrees");
|
|
||||||
|
|
||||||
// Checking tree
|
|
||||||
$files = $repository->getTree('master')->output();
|
|
||||||
|
|
||||||
$this->assertEquals('folder', $files[0]['type']);
|
|
||||||
$this->assertEquals('MyFolder', $files[0]['name']);
|
|
||||||
$this->assertEquals('', $files[0]['size']);
|
|
||||||
$this->assertEquals('040000', $files[0]['mode']);
|
|
||||||
$this->assertEquals('4143e982237f3bdf56b5350f862c334054aad69e', $files[0]['hash']);
|
|
||||||
|
|
||||||
$this->assertEquals('folder', $files[1]['type']);
|
|
||||||
$this->assertEquals('MyTest', $files[1]['name']);
|
|
||||||
$this->assertEquals('', $files[1]['size']);
|
|
||||||
$this->assertEquals('040000', $files[1]['mode']);
|
|
||||||
$this->assertEquals('632240595eabd59e4217d196d6c12efb81f9c011', $files[1]['hash']);
|
|
||||||
|
|
||||||
$this->assertEquals('blob', $files[2]['type']);
|
|
||||||
$this->assertEquals('test_file.txt', $files[2]['name']);
|
|
||||||
$this->assertEquals('55', $files[2]['size']);
|
|
||||||
$this->assertEquals('100644', $files[2]['mode']);
|
|
||||||
$this->assertEquals('a773bfc0fda6f878e3d17d78c667d18297c8831f', $files[2]['hash']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingBlobsWithinTrees()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$files = $repository->getTree('master:MyFolder/')->output();
|
|
||||||
|
|
||||||
$this->assertEquals('folder', $files[0]['type']);
|
|
||||||
$this->assertEquals('Tests', $files[0]['name']);
|
|
||||||
$this->assertEquals('', $files[0]['size']);
|
|
||||||
$this->assertEquals('040000', $files[0]['mode']);
|
|
||||||
$this->assertEquals('8542f67d011ff2ea5ec49a729ba81a52935676d1', $files[0]['hash']);
|
|
||||||
|
|
||||||
$this->assertEquals('blob', $files[1]['type']);
|
|
||||||
$this->assertEquals('crazy.php', $files[1]['name']);
|
|
||||||
$this->assertEquals('26', $files[1]['size']);
|
|
||||||
$this->assertEquals('100644', $files[1]['mode']);
|
|
||||||
$this->assertEquals('d781006b2d05cc31751954a0fb920c990e825aad', $files[1]['hash']);
|
|
||||||
|
|
||||||
$this->assertEquals('blob', $files[2]['type']);
|
|
||||||
$this->assertEquals('skywalker.php', $files[2]['name']);
|
|
||||||
$this->assertEquals('26', $files[2]['size']);
|
|
||||||
$this->assertEquals('100644', $files[2]['mode']);
|
|
||||||
$this->assertEquals('d781006b2d05cc31751954a0fb920c990e825aad', $files[2]['hash']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingBlobOutput()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$blob = $repository->getBlob('master:MyFolder/crazy.php')->output();
|
|
||||||
$this->assertEquals('Lorem ipsum dolor sit amet', $blob);
|
|
||||||
|
|
||||||
$blob = $repository->getBlob('master:test_file4.txt')->output();
|
|
||||||
$this->assertEquals('Your mother is so ugly, glCullFace always returns TRUE.', $blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingStatistics()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$stats = $repository->getStatistics('master');
|
|
||||||
|
|
||||||
$this->assertEquals('10', $stats['extensions']['.txt']);
|
|
||||||
$this->assertEquals('5', $stats['extensions']['.php']);
|
|
||||||
$this->assertEquals('680', $stats['size']);
|
|
||||||
$this->assertEquals('15', $stats['files']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingAuthorStatistics()
|
|
||||||
{
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$stats = $repository->getAuthorStatistics();
|
|
||||||
|
|
||||||
$this->assertEquals('Luke Skywalker', $stats[0]['name']);
|
|
||||||
$this->assertEquals('luke@rebel.org', $stats[0]['email']);
|
|
||||||
$this->assertEquals('2', $stats[0]['commits']);
|
|
||||||
|
|
||||||
$repository->setConfig('user.name', 'Princess Leia');
|
|
||||||
$repository->setConfig('user.email', 'sexyleia@republic.com');
|
|
||||||
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit AMET');
|
|
||||||
$repository->addAll();
|
|
||||||
$repository->commit("Fixing AMET case");
|
|
||||||
|
|
||||||
$stats = $repository->getAuthorStatistics();
|
|
||||||
|
|
||||||
$this->assertEquals('Luke Skywalker', $stats[0]['name']);
|
|
||||||
$this->assertEquals('luke@rebel.org', $stats[0]['email']);
|
|
||||||
$this->assertEquals('2', $stats[0]['commits']);
|
|
||||||
|
|
||||||
$this->assertEquals('Princess Leia', $stats[1]['name']);
|
|
||||||
$this->assertEquals('sexyleia@republic.com', $stats[1]['email']);
|
|
||||||
$this->assertEquals('1', $stats[1]['commits']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingSymlinksWithinTrees()
|
|
||||||
{
|
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
||||||
$this->markTestSkipped('Unable to run on Windows');
|
|
||||||
}
|
|
||||||
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$fs = new Filesystem();
|
|
||||||
$fs->touch(self::$tmpdir . '/testrepo/original_file.txt');
|
|
||||||
$fs->symlink(self::$tmpdir . '/testrepo/original_file.txt', self::$tmpdir . '/testrepo/link.txt');
|
|
||||||
$repository->addAll();
|
|
||||||
$repository->commit("Testing symlinks");
|
|
||||||
$files = $repository->getTree('master');
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file instanceof GitList\Component\Git\Model\Symlink) {
|
|
||||||
$this->assertEquals($file->getPath(), self::$tmpdir . '/testrepo/original_file.txt');
|
|
||||||
$this->assertEquals($file->getName(), 'link.txt');
|
|
||||||
$this->assertEquals($file->getMode(), '120000');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fail('No symlink found inside tree');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsGettingSymlinksWithinTreesOutput()
|
|
||||||
{
|
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
||||||
$this->markTestSkipped('Unable to run on Windows');
|
|
||||||
}
|
|
||||||
|
|
||||||
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
|
|
||||||
$fs = new Filesystem();
|
|
||||||
$fs->touch(self::$tmpdir . '/testrepo/original_file.txt');
|
|
||||||
$fs->symlink(self::$tmpdir . '/testrepo/original_file.txt', self::$tmpdir . '/testrepo/link2.txt');
|
|
||||||
$repository->addAll();
|
|
||||||
$repository->commit("Testing symlinks");
|
|
||||||
$files = $repository->getTree('master')->output();
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file['type'] == 'symlink') {
|
|
||||||
$this->assertEquals($file['path'], self::$tmpdir . '/testrepo/original_file.txt');
|
|
||||||
$this->assertEquals($file['name'], 'link.txt');
|
|
||||||
$this->assertEquals($file['mode'], '120000');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fail('No symlink found inside tree output');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
|
||||||
{
|
|
||||||
$fs = new Filesystem();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$fs->remove(self::$tmpdir);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// Ignore, file is not closed yet
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user