updated-packages
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
@@ -28,13 +29,13 @@ class Admin
|
||||
* @param bool $bare indicate to create a bare repository
|
||||
* @param array $options options for Repository creation
|
||||
*
|
||||
* @return Repository
|
||||
*
|
||||
* @throws RuntimeException Directory exists or not writable (only if debug=true)
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
public static function init($path, $bare = true, array $options = array())
|
||||
public static function init($path, $bare = true, array $options = [])
|
||||
{
|
||||
$process = static::getProcess('init', array_merge(array('-q'), $bare ? array('--bare') : array(), array($path)), $options);
|
||||
$process = static::getProcess('init', array_merge(['-q'], $bare ? ['--bare'] : [], [$path]), $options);
|
||||
|
||||
$process->run();
|
||||
|
||||
@@ -57,9 +58,9 @@ class Admin
|
||||
*
|
||||
* @return bool true if url is valid
|
||||
*/
|
||||
public static function isValidRepository($url, array $options = array())
|
||||
public static function isValidRepository($url, array $options = [])
|
||||
{
|
||||
$process = static::getProcess('ls-remote', array($url), $options);
|
||||
$process = static::getProcess('ls-remote', [$url], $options);
|
||||
|
||||
$process->run();
|
||||
|
||||
@@ -76,9 +77,9 @@ class Admin
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
public static function cloneTo($path, $url, $bare = true, array $options = array())
|
||||
public static function cloneTo($path, $url, $bare = true, array $options = [])
|
||||
{
|
||||
$args = $bare ? array('--bare') : array();
|
||||
$args = $bare ? ['--bare'] : [];
|
||||
|
||||
return static::cloneRepository($path, $url, $args, $options);
|
||||
}
|
||||
@@ -94,9 +95,9 @@ class Admin
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
public static function cloneBranchTo($path, $url, $branch, $bare = true, $options = array())
|
||||
public static function cloneBranchTo($path, $url, $branch, $bare = true, $options = [])
|
||||
{
|
||||
$args = array('--branch', $branch);
|
||||
$args = ['--branch', $branch];
|
||||
if ($bare) {
|
||||
$args[] = '--bare';
|
||||
}
|
||||
@@ -113,9 +114,9 @@ class Admin
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
public static function mirrorTo($path, $url, array $options = array())
|
||||
public static function mirrorTo($path, $url, array $options = [])
|
||||
{
|
||||
return static::cloneRepository($path, $url, array('--mirror'), $options);
|
||||
return static::cloneRepository($path, $url, ['--mirror'], $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,9 +129,9 @@ class Admin
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
public static function cloneRepository($path, $url, array $args = array(), array $options = array())
|
||||
public static function cloneRepository($path, $url, array $args = [], array $options = [])
|
||||
{
|
||||
$process = static::getProcess('clone', array_merge(array('-q'), $args, array($url, $path)), $options);
|
||||
$process = static::getProcess('clone', array_merge(['-q'], $args, [$url, $path]), $options);
|
||||
|
||||
$process->run();
|
||||
|
||||
@@ -144,26 +145,16 @@ class Admin
|
||||
/**
|
||||
* This internal method is used to create a process object.
|
||||
*/
|
||||
private static function getProcess($command, array $args = array(), array $options = array())
|
||||
private static function getProcess($command, array $args = [], array $options = [])
|
||||
{
|
||||
$is_windows = defined('PHP_WINDOWS_VERSION_BUILD');
|
||||
$options = array_merge(array(
|
||||
'environment_variables' => $is_windows ? array('PATH' => getenv('PATH')) : array(),
|
||||
'command' => 'git',
|
||||
'process_timeout' => 3600,
|
||||
), $options);
|
||||
$options = array_merge([
|
||||
'environment_variables' => $is_windows ? ['PATH' => getenv('PATH')] : [],
|
||||
'command' => 'git',
|
||||
'process_timeout' => 3600,
|
||||
], $options);
|
||||
|
||||
$commandline = array_merge(array($options['command'], $command), $args);
|
||||
|
||||
// Backward compatible layer for Symfony Process < 4.0.
|
||||
if (class_exists('Symfony\Component\Process\ProcessBuilder')) {
|
||||
$commandline = implode(' ', array_map(
|
||||
'Symfony\Component\Process\ProcessUtils::escapeArgument',
|
||||
$commandline
|
||||
));
|
||||
}
|
||||
|
||||
$process = new Process($commandline);
|
||||
$process = new Process(array_merge([$options['command'], $command], $args));
|
||||
$process->setEnv($options['environment_variables']);
|
||||
$process->setTimeout($options['process_timeout']);
|
||||
$process->setIdleTimeout($options['process_timeout']);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Blame\Line;
|
||||
@@ -83,33 +84,31 @@ class Blame implements \Countable
|
||||
*/
|
||||
public function getGroupedLines()
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
$commit = null;
|
||||
$current = array();
|
||||
$current = [];
|
||||
|
||||
foreach ($this->getLines() as $lineNumber => $line) {
|
||||
if ($commit !== $line->getCommit()) {
|
||||
if (count($current)) {
|
||||
$result[] = array($commit, $current);
|
||||
$result[] = [$commit, $current];
|
||||
}
|
||||
$commit = $line->getCommit();
|
||||
$current = array();
|
||||
$current = [];
|
||||
}
|
||||
|
||||
$current[$lineNumber] = $line;
|
||||
}
|
||||
|
||||
if (count($current)) {
|
||||
$result[] = array($commit, $current);
|
||||
$result[] = [$commit, $current];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all lines of the blame.
|
||||
*
|
||||
* @return array
|
||||
* @return Line[] All lines of the blame.
|
||||
*/
|
||||
public function getLines()
|
||||
{
|
||||
@@ -117,7 +116,7 @@ class Blame implements \Countable
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
$args = array('-p');
|
||||
$args = ['-p'];
|
||||
|
||||
if (null !== $this->lineRange) {
|
||||
$args[] = '-L';
|
||||
@@ -138,6 +137,7 @@ class Blame implements \Countable
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->getLines());
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Blame;
|
||||
|
||||
use Gitonomy\Git\Commit;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
/**
|
||||
@@ -57,14 +58,14 @@ class Blob
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns content of the blob.
|
||||
*
|
||||
* @throws ProcessException Error occurred while getting content of blob
|
||||
*
|
||||
* @return string Content of the blob.
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if (null === $this->content) {
|
||||
$this->content = $this->repository->run('cat-file', array('-p', $this->hash));
|
||||
$this->content = $this->repository->run('cat-file', ['-p', $this->hash]);
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
|
@@ -9,12 +9,14 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Diff\Diff;
|
||||
use Gitonomy\Git\Exception\InvalidArgumentException;
|
||||
use Gitonomy\Git\Exception\ProcessException;
|
||||
use Gitonomy\Git\Exception\ReferenceNotFoundException;
|
||||
use Gitonomy\Git\Reference\Branch;
|
||||
use Gitonomy\Git\Util\StringHelper;
|
||||
|
||||
/**
|
||||
@@ -29,15 +31,15 @@ class Commit extends Revision
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $data = array();
|
||||
private $data = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Gitonomy\Git\Repository $repository Repository of the commit
|
||||
* @param string $hash Hash of the commit
|
||||
* @param Repository $repository Repository of the commit
|
||||
* @param string $hash Hash of the commit
|
||||
*/
|
||||
public function __construct(Repository $repository, $hash, array $data = array())
|
||||
public function __construct(Repository $repository, $hash, array $data = [])
|
||||
{
|
||||
if (!preg_match('/^[a-f0-9]{40}$/', $hash)) {
|
||||
throw new ReferenceNotFoundException($hash);
|
||||
@@ -60,7 +62,7 @@ class Commit extends Revision
|
||||
*/
|
||||
public function getDiff()
|
||||
{
|
||||
$args = array('-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision);
|
||||
$args = ['-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision];
|
||||
|
||||
$diff = Diff::parse($this->repository->run('diff-tree', $args));
|
||||
$diff->setRepository($this->repository);
|
||||
@@ -90,6 +92,8 @@ class Commit extends Revision
|
||||
|
||||
/**
|
||||
* Returns a fixed-with short hash.
|
||||
*
|
||||
* @return string Short hash
|
||||
*/
|
||||
public function getFixedShortHash($length = 6)
|
||||
{
|
||||
@@ -99,7 +103,7 @@ class Commit extends Revision
|
||||
/**
|
||||
* Returns parent hashes.
|
||||
*
|
||||
* @return array An array of SHA1 hashes
|
||||
* @return string[] An array of SHA1 hashes
|
||||
*/
|
||||
public function getParentHashes()
|
||||
{
|
||||
@@ -109,11 +113,11 @@ class Commit extends Revision
|
||||
/**
|
||||
* Returns the parent commits.
|
||||
*
|
||||
* @return array An array of Commit objects
|
||||
* @return Commit[] An array of Commit objects
|
||||
*/
|
||||
public function getParents()
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->getData('parentHashes') as $parentHash) {
|
||||
$result[] = $this->repository->getCommit($parentHash);
|
||||
}
|
||||
@@ -131,6 +135,9 @@ class Commit extends Revision
|
||||
return $this->getData('treeHash');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tree
|
||||
*/
|
||||
public function getTree()
|
||||
{
|
||||
return $this->getData('tree');
|
||||
@@ -149,7 +156,7 @@ class Commit extends Revision
|
||||
$path = $getWorkingDir.'/'.$path;
|
||||
}
|
||||
|
||||
$result = $this->repository->run('log', array('--format=%H', '-n', 1, $this->revision, '--', $path));
|
||||
$result = $this->repository->run('log', ['--format=%H', '-n', 1, $this->revision, '--', $path]);
|
||||
|
||||
return $this->repository->getCommit(trim($result));
|
||||
}
|
||||
@@ -183,7 +190,7 @@ class Commit extends Revision
|
||||
/**
|
||||
* Resolves all references associated to this commit.
|
||||
*
|
||||
* @return array An array of references (Branch, Tag, Squash)
|
||||
* @return Reference[] An array of references (Branch, Tag, Squash)
|
||||
*/
|
||||
public function resolveReferences()
|
||||
{
|
||||
@@ -196,11 +203,11 @@ class Commit extends Revision
|
||||
* @param bool $local set true to try to locate a commit on local repository
|
||||
* @param bool $remote set true to try to locate a commit on remote repository
|
||||
*
|
||||
* @return array An array of Reference\Branch
|
||||
* @return Reference[]|Branch[] An array of Reference\Branch
|
||||
*/
|
||||
public function getIncludingBranches($local = true, $remote = true)
|
||||
{
|
||||
$arguments = array('--contains', $this->revision);
|
||||
$arguments = ['--contains', $this->revision];
|
||||
|
||||
if ($local && $remote) {
|
||||
$arguments[] = '-a';
|
||||
@@ -213,20 +220,22 @@ class Commit extends Revision
|
||||
try {
|
||||
$result = $this->repository->run('branch', $arguments);
|
||||
} catch (ProcessException $e) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
$branchesName = explode("\n", trim(str_replace('*', '', $result)));
|
||||
$branchesName = array_filter($branchesName, function ($v) { return false === StringHelper::strpos($v, '->');});
|
||||
$branchesName = array_filter($branchesName, function ($v) {
|
||||
return false === StringHelper::strpos($v, '->');
|
||||
});
|
||||
$branchesName = array_map('trim', $branchesName);
|
||||
|
||||
$references = $this->repository->getReferences();
|
||||
|
||||
$branches = array();
|
||||
$branches = [];
|
||||
foreach ($branchesName as $branchName) {
|
||||
if (false === $local) {
|
||||
$branches[] = $references->getRemoteBranch($branchName);
|
||||
@@ -263,7 +272,7 @@ class Commit extends Revision
|
||||
/**
|
||||
* Returns the authoring date.
|
||||
*
|
||||
* @return DateTime A time object
|
||||
* @return \DateTime A time object
|
||||
*/
|
||||
public function getAuthorDate()
|
||||
{
|
||||
@@ -293,7 +302,7 @@ class Commit extends Revision
|
||||
/**
|
||||
* Returns the authoring date.
|
||||
*
|
||||
* @return DateTime A time object
|
||||
* @return \DateTime A time object
|
||||
*/
|
||||
public function getCommitterDate()
|
||||
{
|
||||
@@ -331,7 +340,7 @@ class Commit extends Revision
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCommit()
|
||||
{
|
||||
@@ -345,7 +354,7 @@ class Commit extends Revision
|
||||
}
|
||||
|
||||
if ($name === 'shortHash') {
|
||||
$this->data['shortHash'] = trim($this->repository->run('log', array('--abbrev-commit', '--format=%h', '-n', 1, $this->revision)));
|
||||
$this->data['shortHash'] = trim($this->repository->run('log', ['--abbrev-commit', '--format=%h', '-n', 1, $this->revision]));
|
||||
|
||||
return $this->data['shortHash'];
|
||||
}
|
||||
@@ -377,8 +386,9 @@ class Commit extends Revision
|
||||
}
|
||||
|
||||
$parser = new Parser\CommitParser();
|
||||
|
||||
try {
|
||||
$result = $this->repository->run('cat-file', array('commit', $this->revision));
|
||||
$result = $this->repository->run('cat-file', ['commit', $this->revision]);
|
||||
} catch (ProcessException $e) {
|
||||
throw new ReferenceNotFoundException(sprintf('Can not find reference "%s"', $this->revision));
|
||||
}
|
||||
|
@@ -9,10 +9,14 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
class CommitReference
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $hash;
|
||||
|
||||
public function __construct($hash)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Diff;
|
||||
|
||||
use Gitonomy\Git\Parser\DiffParser;
|
||||
@@ -22,7 +23,7 @@ use Gitonomy\Git\Repository;
|
||||
class Diff
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
* @var File[]
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
@@ -61,18 +62,10 @@ class Diff
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRevisions()
|
||||
{
|
||||
return $this->revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of files modified in the diff's revision.
|
||||
*
|
||||
* @return array An array of Diff\File objects
|
||||
* @return File[] An array of Diff\File objects
|
||||
*/
|
||||
public function getFiles()
|
||||
{
|
||||
@@ -96,14 +89,15 @@ class Diff
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'rawDiff' => $this->rawDiff,
|
||||
'files' => array_map(
|
||||
'files' => array_map(
|
||||
function (File $file) {
|
||||
return $file->toArray();
|
||||
}, $this->files
|
||||
},
|
||||
$this->files
|
||||
),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +113,8 @@ class Diff
|
||||
array_map(
|
||||
function ($array) {
|
||||
return File::fromArray($array);
|
||||
}, $array['files']
|
||||
},
|
||||
$array['files']
|
||||
),
|
||||
$array['rawDiff']
|
||||
);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Diff;
|
||||
|
||||
use Gitonomy\Git\Repository;
|
||||
@@ -54,7 +55,7 @@ class File
|
||||
protected $isBinary;
|
||||
|
||||
/**
|
||||
* @var array An array of FileChange objects
|
||||
* @var FileChange[] An array of FileChange objects
|
||||
*/
|
||||
protected $changes;
|
||||
|
||||
@@ -76,7 +77,7 @@ class File
|
||||
$this->newIndex = $newIndex;
|
||||
$this->isBinary = $isBinary;
|
||||
|
||||
$this->changes = array();
|
||||
$this->changes = [];
|
||||
}
|
||||
|
||||
public function addChange(FileChange $change)
|
||||
@@ -214,6 +215,9 @@ class File
|
||||
return $this->isBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FileChange[]
|
||||
*/
|
||||
public function getChanges()
|
||||
{
|
||||
return $this->changes;
|
||||
@@ -221,20 +225,23 @@ class File
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
'old_name' => $this->oldName,
|
||||
'new_name' => $this->newName,
|
||||
'old_mode' => $this->oldMode,
|
||||
'new_mode' => $this->newMode,
|
||||
return [
|
||||
'old_name' => $this->oldName,
|
||||
'new_name' => $this->newName,
|
||||
'old_mode' => $this->oldMode,
|
||||
'new_mode' => $this->newMode,
|
||||
'old_index' => $this->oldIndex,
|
||||
'new_index' => $this->newIndex,
|
||||
'is_binary' => $this->isBinary,
|
||||
'changes' => array_map(function (FileChange $change) {
|
||||
'changes' => array_map(function (FileChange $change) {
|
||||
return $change->toArray();
|
||||
}, $this->changes),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return File
|
||||
*/
|
||||
public static function fromArray(array $array)
|
||||
{
|
||||
$file = new self($array['old_name'], $array['new_name'], $array['old_mode'], $array['new_mode'], $array['old_index'], $array['new_index'], $array['is_binary']);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Diff;
|
||||
|
||||
class FileChange
|
||||
@@ -23,6 +24,15 @@ class FileChange
|
||||
protected $rangeNewCount;
|
||||
protected $lines;
|
||||
|
||||
/**
|
||||
* @param int $rangeOldStart
|
||||
* @param int $rangeOldCount
|
||||
* @param int $rangeNewStart
|
||||
* @param int $rangeNewCount
|
||||
* @param array $lines
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $rangeNewCount, $lines)
|
||||
{
|
||||
$this->rangeOldStart = $rangeOldStart;
|
||||
@@ -32,54 +42,80 @@ class FileChange
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCount($type)
|
||||
{
|
||||
$result = 0;
|
||||
foreach ($this->lines as $line) {
|
||||
if ($line[0] === $type) {
|
||||
++$result;
|
||||
$result++;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRangeOldStart()
|
||||
{
|
||||
return $this->rangeOldStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRangeOldCount()
|
||||
{
|
||||
return $this->rangeOldCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRangeNewStart()
|
||||
{
|
||||
return $this->rangeNewStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRangeNewCount()
|
||||
{
|
||||
return $this->rangeNewCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLines()
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'range_old_start' => $this->rangeOldStart,
|
||||
'range_old_count' => $this->rangeOldCount,
|
||||
'range_new_start' => $this->rangeNewStart,
|
||||
'range_new_count' => $this->rangeNewCount,
|
||||
'lines' => $this->lines,
|
||||
);
|
||||
'lines' => $this->lines,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromArray(array $array)
|
||||
{
|
||||
return new self($array['range_old_start'], $array['range_old_count'], $array['range_new_start'], $array['range_new_count'], $array['lines']);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Exception;
|
||||
|
||||
interface GitExceptionInterface
|
||||
|
@@ -10,7 +10,8 @@ class ProcessException extends RuntimeException implements GitExceptionInterface
|
||||
|
||||
public function __construct(Process $process)
|
||||
{
|
||||
parent::__construct("Error while running git command:\n".
|
||||
parent::__construct(
|
||||
"Error while running git command:\n".
|
||||
$process->getCommandLine()."\n".
|
||||
"\n".
|
||||
$process->getErrorOutput()."\n".
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Exception;
|
||||
|
||||
class ReferenceNotFoundException extends \InvalidArgumentException implements GitExceptionInterface
|
||||
|
@@ -9,10 +9,12 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\InvalidArgumentException;
|
||||
use Gitonomy\Git\Exception\LogicException;
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Hooks collection, aggregated by repository.
|
||||
@@ -22,7 +24,7 @@ use Gitonomy\Git\Exception\LogicException;
|
||||
class Hooks
|
||||
{
|
||||
/**
|
||||
* @var Gitonomy\Git\Repository
|
||||
* @var \Gitonomy\Git\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
@@ -51,9 +53,9 @@ class Hooks
|
||||
*
|
||||
* @param string $name Name of the hook
|
||||
*
|
||||
* @return string Content of the hook
|
||||
*
|
||||
* @throws InvalidArgumentException Hook does not exist
|
||||
*
|
||||
* @return string Content of the hook
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
@@ -81,7 +83,7 @@ class Hooks
|
||||
|
||||
$path = $this->getPath($name);
|
||||
if (false === symlink($file, $path)) {
|
||||
throw new RuntimeException(sprintf('Unable to create hook "%s"', $name, $path));
|
||||
throw new RuntimeException(sprintf('Unable to create hook "%s" (%s)', $name, $path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +122,9 @@ class Hooks
|
||||
unlink($this->getPath($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPath($name)
|
||||
{
|
||||
return $this->repository->getGitDir().'/hooks/'.$name;
|
||||
|
21
vendor/gitonomy/gitlib/src/Gitonomy/Git/Log.php
vendored
21
vendor/gitonomy/gitlib/src/Gitonomy/Git/Log.php
vendored
@@ -9,8 +9,10 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Diff\Diff;
|
||||
use Gitonomy\Git\Exception\ProcessException;
|
||||
use Gitonomy\Git\Exception\ReferenceNotFoundException;
|
||||
use Gitonomy\Git\Util\StringHelper;
|
||||
@@ -61,9 +63,9 @@ class Log implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
if (null === $paths) {
|
||||
$paths = array();
|
||||
$paths = [];
|
||||
} elseif (is_string($paths)) {
|
||||
$paths = array($paths);
|
||||
$paths = [$paths];
|
||||
} elseif (!is_array($paths)) {
|
||||
throw new \InvalidArgumentException(sprintf('Expected a string or an array, got a "%s".', is_object($paths) ? get_class($paths) : gettype($paths)));
|
||||
}
|
||||
@@ -135,6 +137,9 @@ class Log implements \Countable, \IteratorAggregate
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Commit
|
||||
*/
|
||||
public function getSingleCommit()
|
||||
{
|
||||
$limit = $this->limit;
|
||||
@@ -150,11 +155,11 @@ class Log implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return Commit[]
|
||||
*/
|
||||
public function getCommits()
|
||||
{
|
||||
$args = array('--encoding='.StringHelper::getEncoding(), '--format=raw');
|
||||
$args = ['--encoding='.StringHelper::getEncoding(), '--format=raw'];
|
||||
|
||||
if (null !== $this->offset) {
|
||||
$args[] = '--skip='.((int) $this->offset);
|
||||
@@ -184,7 +189,7 @@ class Log implements \Countable, \IteratorAggregate
|
||||
$parser = new Parser\LogParser();
|
||||
$parser->parse($output);
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($parser->log as $commitData) {
|
||||
$hash = $commitData['id'];
|
||||
unset($commitData['id']);
|
||||
@@ -201,6 +206,7 @@ class Log implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* @see Countable
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return $this->countCommits();
|
||||
@@ -209,6 +215,7 @@ class Log implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* @see IteratorAggregate
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->getCommits());
|
||||
@@ -222,9 +229,9 @@ class Log implements \Countable, \IteratorAggregate
|
||||
public function countCommits()
|
||||
{
|
||||
if (null !== $this->revisions && count($this->revisions)) {
|
||||
$output = $this->repository->run('rev-list', array_merge(array('--count'), $this->revisions->getAsTextArray(), array('--'), $this->paths));
|
||||
$output = $this->repository->run('rev-list', array_merge(['--count'], $this->revisions->getAsTextArray(), ['--'], $this->paths));
|
||||
} else {
|
||||
$output = $this->repository->run('rev-list', array_merge(array('--count', '--all', '--'), $this->paths));
|
||||
$output = $this->repository->run('rev-list', array_merge(['--count', '--all', '--'], $this->paths));
|
||||
}
|
||||
|
||||
return (int) $output;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
use Gitonomy\Git\Blame\Line;
|
||||
@@ -27,9 +28,9 @@ class BlameParser extends ParserBase
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
$this->lines = array();
|
||||
$this->lines = [];
|
||||
|
||||
$memory = array();
|
||||
$memory = [];
|
||||
|
||||
$line = 1;
|
||||
while (!$this->isFinished()) {
|
||||
@@ -43,9 +44,9 @@ class BlameParser extends ParserBase
|
||||
$this->consumeNewLine();
|
||||
|
||||
if (!isset($memory[$hash])) {
|
||||
foreach (array('author', 'author-mail', 'author-time', 'author-tz',
|
||||
foreach (['author', 'author-mail', 'author-time', 'author-tz',
|
||||
'committer', 'committer-mail', 'committer-time', 'committer-tz',
|
||||
'summary', ) as $key) {
|
||||
'summary', ] as $key) {
|
||||
$this->consume($key);
|
||||
$this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
@@ -68,7 +69,7 @@ class BlameParser extends ParserBase
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->lines[$line] = new Line($memory[$hash], $sourceLine, $targetLine, $blockLine, $content);
|
||||
++$line;
|
||||
$line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
@@ -31,7 +32,7 @@ class CommitParser extends ParserBase
|
||||
$this->tree = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->parents = array();
|
||||
$this->parents = [];
|
||||
while ($this->expects('parent ')) {
|
||||
$this->parents[] = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
@@ -63,7 +64,7 @@ class CommitParser extends ParserBase
|
||||
|
||||
$this->cursor += strlen($vars[1]);
|
||||
|
||||
return array($vars[2], $vars[3], $vars[4]);
|
||||
return [$vars[2], $vars[3], $vars[4]];
|
||||
}
|
||||
|
||||
protected function parseDate($text)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
use Gitonomy\Git\Diff\File;
|
||||
@@ -20,11 +21,11 @@ class DiffParser extends ParserBase
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
$this->files = array();
|
||||
$this->files = [];
|
||||
|
||||
while (!$this->isFinished()) {
|
||||
// 1. title
|
||||
$vars = $this->consumeRegexp('/diff --git (a\/.*) (b\/.*)\n/');
|
||||
$vars = $this->consumeRegexp("/diff --git \"?(a\/.*?)\"? \"?(b\/.*?)\"?\n/");
|
||||
$oldName = $vars[1];
|
||||
$newName = $vars[2];
|
||||
$oldIndex = null;
|
||||
@@ -73,14 +74,15 @@ class DiffParser extends ParserBase
|
||||
}
|
||||
$this->consumeNewLine();
|
||||
|
||||
//verifying if the file was deleted or created
|
||||
if ($this->expects('--- ')) {
|
||||
$oldName = $this->consumeTo("\n");
|
||||
$oldName = $this->consumeTo("\n") === '/dev/null' ? '/dev/null' : $oldName;
|
||||
$this->consumeNewLine();
|
||||
$this->consume('+++ ');
|
||||
$newName = $this->consumeTo("\n");
|
||||
$newName = $this->consumeTo("\n") === '/dev/null' ? '/dev/null' : $newName;
|
||||
$this->consumeNewLine();
|
||||
} elseif ($this->expects('Binary files ')) {
|
||||
$vars = $this->consumeRegexp('/(.*) and (.*) differ\n/');
|
||||
$vars = $this->consumeRegexp('/"?(.*?)"? and "?(.*?)"? differ\n/');
|
||||
$isBinary = true;
|
||||
$oldName = $vars[1];
|
||||
$newName = $vars[2];
|
||||
@@ -89,6 +91,9 @@ class DiffParser extends ParserBase
|
||||
|
||||
$oldName = $oldName === '/dev/null' ? null : substr($oldName, 2);
|
||||
$newName = $newName === '/dev/null' ? null : substr($newName, 2);
|
||||
|
||||
$oldIndex = $oldIndex !== null ?: '';
|
||||
$newIndex = $newIndex !== null ?: '';
|
||||
$oldIndex = preg_match('/^0+$/', $oldIndex) ? null : $oldIndex;
|
||||
$newIndex = preg_match('/^0+$/', $newIndex) ? null : $newIndex;
|
||||
$file = new File($oldName, $newName, $oldMode, $newMode, $oldIndex, $newIndex, $isBinary);
|
||||
@@ -96,23 +101,23 @@ class DiffParser extends ParserBase
|
||||
// 5. Diff
|
||||
while ($this->expects('@@ ')) {
|
||||
$vars = $this->consumeRegexp('/-(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/');
|
||||
$rangeOldStart = $vars[1];
|
||||
$rangeOldCount = $vars[2];
|
||||
$rangeNewStart = $vars[3];
|
||||
$rangeNewCount = isset($vars[4]) ? $vars[4] : $vars[2]; // @todo Ici, t'as pris un gros raccourci mon loulou
|
||||
$rangeOldStart = (int) $vars[1];
|
||||
$rangeOldCount = (int) $vars[2];
|
||||
$rangeNewStart = (int) $vars[3];
|
||||
$rangeNewCount = isset($vars[4]) ? (int) $vars[4] : (int) $vars[2]; // @todo Ici, t'as pris un gros raccourci mon loulou
|
||||
$this->consume(' @@');
|
||||
$this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
|
||||
// 6. Lines
|
||||
$lines = array();
|
||||
$lines = [];
|
||||
while (true) {
|
||||
if ($this->expects(' ')) {
|
||||
$lines[] = array(FileChange::LINE_CONTEXT, $this->consumeTo("\n"));
|
||||
$lines[] = [FileChange::LINE_CONTEXT, $this->consumeTo("\n")];
|
||||
} elseif ($this->expects('+')) {
|
||||
$lines[] = array(FileChange::LINE_ADD, $this->consumeTo("\n"));
|
||||
$lines[] = [FileChange::LINE_ADD, $this->consumeTo("\n")];
|
||||
} elseif ($this->expects('-')) {
|
||||
$lines[] = array(FileChange::LINE_REMOVE, $this->consumeTo("\n"));
|
||||
$lines[] = [FileChange::LINE_REMOVE, $this->consumeTo("\n")];
|
||||
} elseif ($this->expects("\ No newline at end of file")) {
|
||||
// Ignore this case...
|
||||
} else {
|
||||
|
@@ -9,18 +9,19 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
class LogParser extends CommitParser
|
||||
{
|
||||
public $log = array();
|
||||
public $log = [];
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
$this->log = array();
|
||||
$this->log = [];
|
||||
|
||||
while (!$this->isFinished()) {
|
||||
$commit = array();
|
||||
$commit = [];
|
||||
$this->consume('commit ');
|
||||
$commit['id'] = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
@@ -29,7 +30,7 @@ class LogParser extends CommitParser
|
||||
$commit['treeHash'] = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
|
||||
$commit['parentHashes'] = array();
|
||||
$commit['parentHashes'] = [];
|
||||
while ($this->expects('parent ')) {
|
||||
$commit['parentHashes'][] = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
@@ -58,8 +59,7 @@ class LogParser extends CommitParser
|
||||
$message .= $this->consumeTo("\n")."\n";
|
||||
$this->consumeNewLine();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->cursor--;
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
@@ -58,7 +59,7 @@ abstract class ParserBase
|
||||
|
||||
protected function consumeShortHash()
|
||||
{
|
||||
if (!preg_match('/([A-Za-z0-9]{7,40})/A', $this->content, $vars, null, $this->cursor)) {
|
||||
if (!preg_match('/([A-Za-z0-9]{7,40})/A', $this->content, $vars, 0, $this->cursor)) {
|
||||
throw new RuntimeException('No short hash found: '.substr($this->content, $this->cursor, 7));
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ abstract class ParserBase
|
||||
|
||||
protected function consumeHash()
|
||||
{
|
||||
if (!preg_match('/([A-Za-z0-9]{40})/A', $this->content, $vars, null, $this->cursor)) {
|
||||
if (!preg_match('/([A-Za-z0-9]{40})/A', $this->content, $vars, 0, $this->cursor)) {
|
||||
throw new RuntimeException('No hash found: '.substr($this->content, $this->cursor, 40));
|
||||
}
|
||||
|
||||
@@ -80,8 +81,8 @@ abstract class ParserBase
|
||||
|
||||
protected function consumeRegexp($regexp)
|
||||
{
|
||||
if (!preg_match($regexp.'A', $this->content, $vars, null, $this->cursor)) {
|
||||
throw new RuntimeException('No match for regexp '.$regexp.' Upcoming: '.substr($this->content, $this->cursor, 30));
|
||||
if (!preg_match($regexp.'A', $this->content, $vars, 0, $this->cursor)) {
|
||||
throw new RuntimeException('No match for regexp '.$regexp.' Upcoming: '.substr($this->content, $this->cursor, 500));
|
||||
}
|
||||
|
||||
$this->cursor += strlen($vars[0]);
|
||||
@@ -123,11 +124,12 @@ abstract class ParserBase
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function consumeGPGSignature() {
|
||||
protected function consumeGPGSignature()
|
||||
{
|
||||
$expected = "\ngpgsig ";
|
||||
$length = strlen($expected);
|
||||
$actual = substr($this->content, $this->cursor, $length);
|
||||
if($actual != $expected) {
|
||||
if ($actual != $expected) {
|
||||
return '';
|
||||
}
|
||||
$this->cursor += $length;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
class ReferenceParser extends ParserBase
|
||||
@@ -17,14 +18,14 @@ class ReferenceParser extends ParserBase
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
$this->references = array();
|
||||
$this->references = [];
|
||||
|
||||
while (!$this->isFinished()) {
|
||||
$hash = $this->consumeHash();
|
||||
$this->consume(' ');
|
||||
$name = $this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
$this->references[] = array($hash, $name);
|
||||
$this->references[] = [$hash, $name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
91
vendor/gitonomy/gitlib/src/Gitonomy/Git/Parser/TagParser.php
vendored
Normal file
91
vendor/gitonomy/gitlib/src/Gitonomy/Git/Parser/TagParser.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of Gitonomy.
|
||||
*
|
||||
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
* (c) Julien DIDIER <genzo.wm@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
|
||||
class TagParser extends ParserBase
|
||||
{
|
||||
public $object;
|
||||
public $type;
|
||||
public $tag;
|
||||
public $taggerName;
|
||||
public $taggerEmail;
|
||||
public $taggerDate;
|
||||
public $gpgSignature;
|
||||
public $message;
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
$this->consume('object ');
|
||||
$this->object = $this->consumeHash();
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->consume('type ');
|
||||
$this->type = $this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->consume('tag ');
|
||||
$this->tag = $this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->consume('tagger ');
|
||||
list($this->taggerName, $this->taggerEmail, $this->taggerDate) = $this->consumeNameEmailDate();
|
||||
$this->taggerDate = $this->parseDate($this->taggerDate);
|
||||
|
||||
$this->consumeNewLine();
|
||||
$this->consumeNewLine();
|
||||
|
||||
try {
|
||||
$this->message = $this->consumeTo('-----BEGIN PGP SIGNATURE-----');
|
||||
$this->gpgSignature = $this->consumeGPGSignature();
|
||||
} catch (RuntimeException $e) {
|
||||
$this->message = $this->consumeAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected function consumeGPGSignature()
|
||||
{
|
||||
$expected = '-----BEGIN PGP SIGNATURE-----';
|
||||
$length = strlen($expected);
|
||||
$actual = substr($this->content, $this->cursor, $length);
|
||||
if ($actual != $expected) {
|
||||
return '';
|
||||
}
|
||||
$this->cursor += $length;
|
||||
|
||||
return $this->consumeTo('-----END PGP SIGNATURE-----');
|
||||
}
|
||||
|
||||
protected function consumeNameEmailDate()
|
||||
{
|
||||
if (!preg_match('/(([^\n]*) <([^\n]*)> (\d+ [+-]\d{4}))/A', $this->content, $vars, 0, $this->cursor)) {
|
||||
throw new RuntimeException('Unable to parse name, email and date');
|
||||
}
|
||||
|
||||
$this->cursor += strlen($vars[1]);
|
||||
|
||||
return [$vars[2], $vars[3], $vars[4]];
|
||||
}
|
||||
|
||||
protected function parseDate($text)
|
||||
{
|
||||
$date = \DateTime::createFromFormat('U e O', $text.' UTC');
|
||||
|
||||
if (!$date instanceof \DateTime) {
|
||||
throw new RuntimeException(sprintf('Unable to convert "%s" to datetime', $text));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
}
|
@@ -9,11 +9,12 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Parser;
|
||||
|
||||
class TreeParser extends ParserBase
|
||||
{
|
||||
public $entries = array();
|
||||
public $entries = [];
|
||||
|
||||
protected function doParse()
|
||||
{
|
||||
@@ -32,7 +33,7 @@ class TreeParser extends ParserBase
|
||||
$name = $this->consumeTo("\n");
|
||||
$this->consumeNewLine();
|
||||
|
||||
$this->entries[] = array($mode, $type, $hash, $name);
|
||||
$this->entries[] = [$mode, $type, $hash, $name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\LogicException;
|
||||
@@ -23,6 +24,10 @@ class PushReference
|
||||
{
|
||||
const ZERO = '0000000000000000000000000000000000000000';
|
||||
|
||||
/**
|
||||
* @var Repository
|
||||
*/
|
||||
protected $repository;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -85,18 +90,21 @@ class PushReference
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return Log
|
||||
*/
|
||||
public function getLog($excludes = array())
|
||||
public function getLog($excludes = [])
|
||||
{
|
||||
return $this->repository->getLog(array_merge(
|
||||
array($this->getRevision()),
|
||||
[$this->getRevision()],
|
||||
array_map(function ($e) {
|
||||
return '^'.$e;
|
||||
}, $excludes)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRevision()
|
||||
{
|
||||
if ($this->isDelete()) {
|
||||
@@ -159,10 +167,10 @@ class PushReference
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->repository->run('merge-base', array(
|
||||
$result = $this->repository->run('merge-base', [
|
||||
$this->before,
|
||||
$this->after,
|
||||
));
|
||||
]);
|
||||
|
||||
return $this->before !== trim($result);
|
||||
}
|
||||
|
@@ -9,8 +9,12 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\ProcessException;
|
||||
use Gitonomy\Git\Exception\ReferenceNotFoundException;
|
||||
|
||||
/**
|
||||
* Reference in a Git repository.
|
||||
*
|
||||
@@ -28,16 +32,25 @@ abstract class Reference extends Revision
|
||||
$this->commitHash = $commitHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFullname()
|
||||
{
|
||||
return $this->revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->repository->getReferences()->delete($this->getFullname());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCommitHash()
|
||||
{
|
||||
if (null !== $this->commitHash) {
|
||||
@@ -45,7 +58,7 @@ abstract class Reference extends Revision
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->repository->run('rev-parse', array('--verify', $this->revision));
|
||||
$result = $this->repository->run('rev-parse', ['--verify', $this->revision]);
|
||||
} catch (ProcessException $e) {
|
||||
throw new ReferenceNotFoundException(sprintf('Can not find revision "%s"', $this->revision));
|
||||
}
|
||||
@@ -54,15 +67,16 @@ abstract class Reference extends Revision
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the commit associated to the reference.
|
||||
*
|
||||
* @return Commit
|
||||
* @return Commit Commit associated to the reference.
|
||||
*/
|
||||
public function getCommit()
|
||||
{
|
||||
return $this->repository->getCommit($this->getCommitHash());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Commit
|
||||
*/
|
||||
public function getLastModification($path = null)
|
||||
{
|
||||
return $this->getCommit()->getLastModification($path);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Reference;
|
||||
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Reference;
|
||||
|
||||
use Gitonomy\Git\Reference;
|
||||
|
@@ -9,18 +9,26 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Reference;
|
||||
|
||||
use Gitonomy\Git\Commit;
|
||||
use Gitonomy\Git\Exception\ProcessException;
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
use Gitonomy\Git\Parser\ReferenceParser;
|
||||
use Gitonomy\Git\Parser\TagParser;
|
||||
use Gitonomy\Git\Reference;
|
||||
|
||||
/**
|
||||
* Representation of a tag reference.
|
||||
*
|
||||
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
* @author Bruce Wells <brucekwells@gmail.com>
|
||||
*/
|
||||
class Tag extends Reference
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
if (!preg_match('#^refs/tags/(.*)$#', $this->revision, $vars)) {
|
||||
@@ -29,4 +37,180 @@ class Tag extends Reference
|
||||
|
||||
return $vars[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tag is annotated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAnnotated()
|
||||
{
|
||||
try {
|
||||
$this->repository->run('cat-file', ['tag', $this->revision]);
|
||||
} catch (ProcessException $e) {
|
||||
return false; // Is not an annotated tag
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the actual commit associated with the tag, and not the hash of the tag if annotated.
|
||||
*
|
||||
* @return Commit
|
||||
*/
|
||||
public function getCommit()
|
||||
{
|
||||
if ($this->isAnnotated()) {
|
||||
try {
|
||||
$output = $this->repository->run('show-ref', ['-d', '--tag', $this->revision]);
|
||||
$parser = new ReferenceParser();
|
||||
$parser->parse($output);
|
||||
|
||||
foreach ($parser->references as list($row)) {
|
||||
$commitHash = $row;
|
||||
}
|
||||
|
||||
return $this->repository->getCommit($commitHash);
|
||||
} catch (ProcessException $e) {
|
||||
// ignore the exception
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getCommit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tagger name.
|
||||
*
|
||||
* @return string A name
|
||||
*/
|
||||
public function getTaggerName()
|
||||
{
|
||||
return $this->getData('taggerName');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comitter email.
|
||||
*
|
||||
* @return string An email
|
||||
*/
|
||||
public function getTaggerEmail()
|
||||
{
|
||||
return $this->getData('taggerEmail');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authoring date.
|
||||
*
|
||||
* @return \DateTime A time object
|
||||
*/
|
||||
public function getTaggerDate()
|
||||
{
|
||||
return $this->getData('taggerDate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message of the commit.
|
||||
*
|
||||
* @return string A tag message
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->getData('message');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subject message (the first line).
|
||||
*
|
||||
* @return string The subject message
|
||||
*/
|
||||
public function getSubjectMessage()
|
||||
{
|
||||
return $this->getData('subjectMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the body message.
|
||||
*
|
||||
* @return string The body message
|
||||
*/
|
||||
public function getBodyMessage()
|
||||
{
|
||||
return $this->getData('bodyMessage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the GPG signature.
|
||||
*
|
||||
* @return string The GPG signature
|
||||
*/
|
||||
public function getGPGSignature()
|
||||
{
|
||||
return $this->getData('gpgSignature');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether tag is signed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSigned()
|
||||
{
|
||||
try {
|
||||
$this->getGPGSignature();
|
||||
|
||||
return true;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getData($name)
|
||||
{
|
||||
if (!$this->isAnnotated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
if ($name === 'subjectMessage') {
|
||||
$lines = explode("\n", $this->getData('message'));
|
||||
$this->data['subjectMessage'] = reset($lines);
|
||||
|
||||
return $this->data['subjectMessage'];
|
||||
}
|
||||
|
||||
if ($name === 'bodyMessage') {
|
||||
$message = $this->getData('message');
|
||||
|
||||
$lines = explode("\n", $message);
|
||||
|
||||
array_shift($lines);
|
||||
array_pop($lines);
|
||||
|
||||
$data['bodyMessage'] = implode("\n", $lines);
|
||||
|
||||
return $data['bodyMessage'];
|
||||
}
|
||||
|
||||
$parser = new TagParser();
|
||||
$result = $this->repository->run('cat-file', ['tag', $this->revision]);
|
||||
|
||||
$parser->parse($result);
|
||||
|
||||
$this->data['taggerName'] = $parser->taggerName;
|
||||
$this->data['taggerEmail'] = $parser->taggerEmail;
|
||||
$this->data['taggerDate'] = $parser->taggerDate;
|
||||
$this->data['message'] = $parser->message;
|
||||
$this->data['gpgSignature'] = $parser->gpgSignature;
|
||||
|
||||
if (!isset($this->data[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('No data named "%s" in Tag.', $name));
|
||||
}
|
||||
|
||||
return $this->data[$name];
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\ReferenceNotFoundException;
|
||||
@@ -28,7 +29,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* Repository object.
|
||||
*
|
||||
* @var Gitonomy\Git\Repository
|
||||
* @var Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
@@ -42,14 +43,14 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* List with all tags.
|
||||
*
|
||||
* @var array
|
||||
* @var Tag[]
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
/**
|
||||
* List with all branches.
|
||||
*
|
||||
* @var array
|
||||
* @var Branch[]
|
||||
*/
|
||||
protected $branches;
|
||||
|
||||
@@ -63,14 +64,14 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Gitonomy\Git\Repository $repository The repository
|
||||
* @param Repository $repository The repository
|
||||
*/
|
||||
public function __construct($repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->references = array();
|
||||
$this->tags = array();
|
||||
$this->branches = array();
|
||||
$this->references = [];
|
||||
$this->tags = [];
|
||||
$this->branches = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +92,9 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
return $this->references[$fullname];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function has($fullname)
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -98,18 +102,24 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
return isset($this->references[$fullname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Reference
|
||||
*/
|
||||
public function update(Reference $reference)
|
||||
{
|
||||
$fullname = $reference->getFullname();
|
||||
|
||||
$this->initialize();
|
||||
$this->repository->run('update-ref', array($fullname, $reference->getCommitHash()));
|
||||
$this->repository->run('update-ref', [$fullname, $reference->getCommitHash()]);
|
||||
|
||||
$this->references[$fullname] = $reference;
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Reference
|
||||
*/
|
||||
public function createBranch($name, $commitHash)
|
||||
{
|
||||
$branch = new Branch($this->repository, 'refs/heads/'.$name, $commitHash);
|
||||
@@ -117,6 +127,9 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
return $this->update($branch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Reference
|
||||
*/
|
||||
public function createTag($name, $commitHash)
|
||||
{
|
||||
$tag = new Tag($this->repository, 'refs/tags/'.$name, $commitHash);
|
||||
@@ -124,13 +137,19 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
return $this->update($tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete($fullname)
|
||||
{
|
||||
$this->repository->run('update-ref', array('-d', $fullname));
|
||||
$this->repository->run('update-ref', ['-d', $fullname]);
|
||||
|
||||
unset($this->references[$fullname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBranches()
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -153,6 +172,9 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
return $this->has('refs/tags/'.$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Branch
|
||||
*/
|
||||
public function getFirstBranch()
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -162,7 +184,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array An array of Tag objects
|
||||
* @return Tag[] An array of Tag objects
|
||||
*/
|
||||
public function resolveTags($hash)
|
||||
{
|
||||
@@ -172,7 +194,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
$hash = $hash->getHash();
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
$tags = [];
|
||||
foreach ($this->references as $reference) {
|
||||
if ($reference instanceof Reference\Tag && $reference->getCommitHash() === $hash) {
|
||||
$tags[] = $reference;
|
||||
@@ -183,7 +205,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array An array of Branch objects
|
||||
* @return Branch[] An array of Branch objects
|
||||
*/
|
||||
public function resolveBranches($hash)
|
||||
{
|
||||
@@ -193,7 +215,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
$hash = $hash->getHash();
|
||||
}
|
||||
|
||||
$branches = array();
|
||||
$branches = [];
|
||||
foreach ($this->references as $reference) {
|
||||
if ($reference instanceof Reference\Branch && $reference->getCommitHash() === $hash) {
|
||||
$branches[] = $reference;
|
||||
@@ -204,7 +226,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array An array of references
|
||||
* @return Reference[] An array of references
|
||||
*/
|
||||
public function resolve($hash)
|
||||
{
|
||||
@@ -214,7 +236,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
$hash = $hash->getHash();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->references as $k => $reference) {
|
||||
if ($reference->getCommitHash() === $hash) {
|
||||
$result[] = $reference;
|
||||
@@ -225,9 +247,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all tags.
|
||||
*
|
||||
* @return array
|
||||
* @return Tag[] All tags.
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
@@ -237,15 +257,13 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all branches.
|
||||
*
|
||||
* @return array
|
||||
* @return Branch[] All branches.
|
||||
*/
|
||||
public function getBranches()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->references as $reference) {
|
||||
if ($reference instanceof Reference\Branch) {
|
||||
$result[] = $reference;
|
||||
@@ -256,13 +274,11 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all locales branches.
|
||||
*
|
||||
* @return array
|
||||
* @return Branch[] All local branches.
|
||||
*/
|
||||
public function getLocalBranches()
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->getBranches() as $branch) {
|
||||
if ($branch->isLocal()) {
|
||||
$result[] = $branch;
|
||||
@@ -273,13 +289,11 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all remote branches.
|
||||
*
|
||||
* @return array
|
||||
* @return Branch[] All remote branches.
|
||||
*/
|
||||
public function getRemoteBranches()
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this->getBranches() as $branch) {
|
||||
if ($branch->isRemote()) {
|
||||
$result[] = $branch;
|
||||
@@ -365,12 +379,6 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
} elseif ($fullname === 'refs/stash') {
|
||||
$reference = new Stash($this->repository, $fullname, $commitHash);
|
||||
$this->references[$fullname] = $reference;
|
||||
} elseif (preg_match('#^refs/pull/(.*)$#', $fullname)) {
|
||||
// Do nothing here
|
||||
} elseif ($fullname === 'refs/notes/gtm-data') {
|
||||
// Do nothing here
|
||||
} else {
|
||||
throw new RuntimeException(sprintf('Unable to parse "%s"', $fullname));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,6 +388,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
*
|
||||
* @see Countable
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -390,6 +399,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* @see IteratorAggregate
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
$this->initialize();
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Diff\Diff;
|
||||
@@ -17,7 +18,6 @@ use Gitonomy\Git\Exception\ProcessException;
|
||||
use Gitonomy\Git\Exception\RuntimeException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\ProcessUtils;
|
||||
|
||||
/**
|
||||
* Git repository object.
|
||||
@@ -86,6 +86,11 @@ class Repository
|
||||
*/
|
||||
protected $environmentVariables;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $inheritEnvironmentVariables;
|
||||
|
||||
/**
|
||||
* Timeout that should be set for every running process.
|
||||
*
|
||||
@@ -111,17 +116,17 @@ class Repository
|
||||
*
|
||||
* @throws InvalidArgumentException The folder does not exists
|
||||
*/
|
||||
public function __construct($dir, $options = array())
|
||||
public function __construct($dir, $options = [])
|
||||
{
|
||||
$is_windows = defined('PHP_WINDOWS_VERSION_BUILD');
|
||||
$options = array_merge(array(
|
||||
'working_dir' => null,
|
||||
'debug' => true,
|
||||
'logger' => null,
|
||||
'environment_variables' => $is_windows ? array('PATH' => getenv('path')) : array(),
|
||||
'command' => 'git',
|
||||
'process_timeout' => 3600,
|
||||
), $options);
|
||||
$options = array_merge([
|
||||
'working_dir' => null,
|
||||
'debug' => true,
|
||||
'logger' => null,
|
||||
'command' => 'git',
|
||||
'environment_variables' => [],
|
||||
'inherit_environment_variables' => false,
|
||||
'process_timeout' => 3600,
|
||||
], $options);
|
||||
|
||||
if (null !== $options['logger'] && !$options['logger'] instanceof LoggerInterface) {
|
||||
throw new InvalidArgumentException(sprintf('Argument "logger" passed to Repository should be a Psr\Log\LoggerInterface. A %s was provided', is_object($options['logger']) ? get_class($options['logger']) : gettype($options['logger'])));
|
||||
@@ -130,11 +135,17 @@ class Repository
|
||||
$this->logger = $options['logger'];
|
||||
$this->initDir($dir, $options['working_dir']);
|
||||
|
||||
$this->objects = array();
|
||||
$this->debug = (bool) $options['debug'];
|
||||
$this->environmentVariables = $options['environment_variables'];
|
||||
$this->processTimeout = $options['process_timeout'];
|
||||
$this->objects = [];
|
||||
$this->command = $options['command'];
|
||||
$this->debug = (bool) $options['debug'];
|
||||
$this->processTimeout = $options['process_timeout'];
|
||||
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD') && isset($_SERVER['PATH']) && !isset($options['environment_variables']['PATH'])) {
|
||||
$options['environment_variables']['PATH'] = $_SERVER['PATH'];
|
||||
}
|
||||
|
||||
$this->environmentVariables = $options['environment_variables'];
|
||||
$this->inheritEnvironmentVariables = $options['inherit_environment_variables'];
|
||||
|
||||
if (true === $this->debug && null !== $this->logger) {
|
||||
$this->logger->debug(sprintf('Repository created (git dir: "%s", working dir: "%s")', $this->gitDir, $this->workingDir ?: 'none'));
|
||||
@@ -153,7 +164,7 @@ class Repository
|
||||
|
||||
if (false === $realGitDir) {
|
||||
throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $gitDir));
|
||||
} else if (!is_dir($realGitDir)) {
|
||||
} elseif (!is_dir($realGitDir)) {
|
||||
throw new InvalidArgumentException(sprintf('Directory "%s" does not exist or is not a directory', $realGitDir));
|
||||
} elseif (null === $workingDir && is_dir($realGitDir.'/.git')) {
|
||||
$workingDir = $realGitDir;
|
||||
@@ -304,11 +315,13 @@ class Repository
|
||||
/**
|
||||
* Returns the reference list associated to the repository.
|
||||
*
|
||||
* @param bool $reload Reload references from the filesystem
|
||||
*
|
||||
* @return ReferenceBag
|
||||
*/
|
||||
public function getReferences()
|
||||
public function getReferences($reload = false)
|
||||
{
|
||||
if (null === $this->referenceBag) {
|
||||
if (null === $this->referenceBag || $reload) {
|
||||
$this->referenceBag = new ReferenceBag($this);
|
||||
}
|
||||
|
||||
@@ -363,6 +376,9 @@ class Repository
|
||||
return $this->objects[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Blame
|
||||
*/
|
||||
public function getBlame($revision, $file, $lineRange = null)
|
||||
{
|
||||
if (is_string($revision)) {
|
||||
@@ -400,7 +416,7 @@ class Repository
|
||||
$revisions = new RevisionList($this, $revisions);
|
||||
}
|
||||
|
||||
$args = array_merge(array('-r', '-p', '-m', '-M', '--no-commit-id', '--full-index'), $revisions->getAsTextArray());
|
||||
$args = array_merge(['-r', '-p', '-m', '-M', '--no-commit-id', '--full-index'], $revisions->getAsTextArray());
|
||||
|
||||
$diff = Diff::parse($this->run('diff', $args));
|
||||
$diff->setRepository($this);
|
||||
@@ -412,31 +428,18 @@ class Repository
|
||||
* Returns the size of repository, in kilobytes.
|
||||
*
|
||||
* @return int A sum, in kilobytes
|
||||
*
|
||||
* @throws RuntimeException An error occurred while computing size
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
$commandlineArguments = array('du', '-skc', $this->gitDir);
|
||||
$commandline = $this->normalizeCommandlineArguments($commandlineArguments);
|
||||
$process = new Process($commandline);
|
||||
$process->run();
|
||||
|
||||
if (!preg_match('/(\d+)\s+total$/', trim($process->getOutput()), $vars)) {
|
||||
$message = sprintf("Unable to parse process output\ncommand: %s\noutput: %s", $process->getCommandLine(), $process->getOutput());
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->error($message);
|
||||
$totalBytes = 0;
|
||||
$path = realpath($this->gitDir);
|
||||
if ($path && file_exists($path)) {
|
||||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object) {
|
||||
$totalBytes += $object->getSize();
|
||||
}
|
||||
|
||||
if (true === $this->debug) {
|
||||
throw new RuntimeException('unable to parse repository size output');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return $vars[1];
|
||||
return (int) ($totalBytes / 1000 + 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,7 +447,7 @@ class Repository
|
||||
*
|
||||
* @param string $command The command to execute
|
||||
*/
|
||||
public function shell($command, array $env = array())
|
||||
public function shell($command, array $env = [])
|
||||
{
|
||||
$argument = sprintf('%s \'%s\'', $command, $this->gitDir);
|
||||
|
||||
@@ -453,7 +456,7 @@ class Repository
|
||||
$prefix .= sprintf('export %s=%s;', escapeshellarg($name), escapeshellarg($value));
|
||||
}
|
||||
|
||||
proc_open($prefix.'git shell -c '.escapeshellarg($argument), array(STDIN, STDOUT, STDERR), $pipes);
|
||||
proc_open($prefix.'git shell -c '.escapeshellarg($argument), [STDIN, STDOUT, STDERR], $pipes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,11 +528,11 @@ class Repository
|
||||
* @param string $command Git command to run (checkout, branch, tag)
|
||||
* @param array $args Arguments of git command
|
||||
*
|
||||
* @return string Output of a successful process or null if execution failed and debug-mode is disabled.
|
||||
*
|
||||
* @throws RuntimeException Error while executing git command (debug-mode only)
|
||||
*
|
||||
* @return string Output of a successful process or null if execution failed and debug-mode is disabled.
|
||||
*/
|
||||
public function run($command, $args = array())
|
||||
public function run($command, $args = [])
|
||||
{
|
||||
$process = $this->getProcess($command, $args);
|
||||
|
||||
@@ -598,7 +601,7 @@ class Repository
|
||||
*
|
||||
* @return Repository the newly created repository
|
||||
*/
|
||||
public function cloneTo($path, $bare = true, array $options = array())
|
||||
public function cloneTo($path, $bare = true, array $options = [])
|
||||
{
|
||||
return Admin::cloneTo($path, $this->gitDir, $bare, $options);
|
||||
}
|
||||
@@ -611,57 +614,27 @@ class Repository
|
||||
*
|
||||
* @see self::run
|
||||
*/
|
||||
private function getProcess($command, $args = array())
|
||||
private function getProcess($command, $args = [])
|
||||
{
|
||||
$base = array($this->command, '--git-dir', $this->gitDir);
|
||||
$base = [$this->command, '--git-dir', $this->gitDir];
|
||||
|
||||
if ($this->workingDir) {
|
||||
$base = array_merge($base, array('--work-tree', $this->workingDir));
|
||||
$base = array_merge($base, ['--work-tree', $this->workingDir]);
|
||||
}
|
||||
|
||||
$base[] = $command;
|
||||
|
||||
$commandlineArguments = array_merge($base, $args);
|
||||
$commandline = $this->normalizeCommandlineArguments($commandlineArguments);
|
||||
$process = new Process(array_merge($base, $args));
|
||||
|
||||
if ($this->inheritEnvironmentVariables) {
|
||||
$process->setEnv(array_replace($_SERVER, $this->environmentVariables));
|
||||
} else {
|
||||
$process->setEnv($this->environmentVariables);
|
||||
}
|
||||
|
||||
$process = new Process($commandline);
|
||||
$process->setEnv($this->environmentVariables);
|
||||
$process->setTimeout($this->processTimeout);
|
||||
$process->setIdleTimeout($this->processTimeout);
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal helper method is used to convert an array of commandline
|
||||
* arguments to an escaped commandline string for older versions of the
|
||||
* Symfony Process component.
|
||||
*
|
||||
* It acts as a backward compatible layer for Symfony Process < 3.3.
|
||||
*
|
||||
* @param array $arguments a list of command line arguments
|
||||
*
|
||||
* @return string|array a single escaped string (< 4.0) or a raw array of
|
||||
* the arguments passed in (4.0+)
|
||||
*
|
||||
* @see Process::escapeArgument()
|
||||
* @see ProcessUtils::escapeArgument()
|
||||
*/
|
||||
private function normalizeCommandlineArguments(array $arguments)
|
||||
{
|
||||
// From version 4.0 and onwards, the Process accepts an array of
|
||||
// arguments, and escaping is taken care of automatically.
|
||||
if (!class_exists('Symfony\Component\Process\ProcessBuilder')) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
// For version < 3.3, the Process only accepts a simple string
|
||||
// as commandline, and escaping has to happen manually.
|
||||
$commandline = implode(' ', array_map(
|
||||
'Symfony\Component\Process\ProcessUtils::escapeArgument',
|
||||
$arguments
|
||||
));
|
||||
|
||||
return $commandline;
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
/**
|
||||
@@ -26,9 +27,9 @@ class RevisionList implements \IteratorAggregate, \Countable
|
||||
public function __construct(Repository $repository, $revisions)
|
||||
{
|
||||
if (is_string($revisions)) {
|
||||
$revisions = array($repository->getRevision($revisions));
|
||||
$revisions = [$repository->getRevision($revisions)];
|
||||
} elseif ($revisions instanceof Revision) {
|
||||
$revisions = array($revisions);
|
||||
$revisions = [$revisions];
|
||||
} elseif (!is_array($revisions)) {
|
||||
throw new \InvalidArgumentException(sprintf('Expected a string, a Revision or an array, got a "%s".', is_object($revisions) ? get_class($revisions) : gettype($revisions)));
|
||||
}
|
||||
@@ -48,16 +49,21 @@ class RevisionList implements \IteratorAggregate, \Countable
|
||||
$this->revisions = $revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Revision[]
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return $this->revisions;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->revisions);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->revisions);
|
||||
|
13
vendor/gitonomy/gitlib/src/Gitonomy/Git/Tree.php
vendored
13
vendor/gitonomy/gitlib/src/Gitonomy/Git/Tree.php
vendored
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Exception\InvalidArgumentException;
|
||||
@@ -41,20 +42,20 @@ class Tree
|
||||
return;
|
||||
}
|
||||
|
||||
$output = $this->repository->run('cat-file', array('-p', $this->hash));
|
||||
$output = $this->repository->run('cat-file', ['-p', $this->hash]);
|
||||
$parser = new Parser\TreeParser();
|
||||
$parser->parse($output);
|
||||
|
||||
$this->entries = array();
|
||||
$this->entries = [];
|
||||
|
||||
foreach ($parser->entries as $entry) {
|
||||
list($mode, $type, $hash, $name) = $entry;
|
||||
if ($type == 'blob') {
|
||||
$this->entries[$name] = array($mode, $this->repository->getBlob($hash));
|
||||
$this->entries[$name] = [$mode, $this->repository->getBlob($hash)];
|
||||
} elseif ($type == 'tree') {
|
||||
$this->entries[$name] = array($mode, $this->repository->getTree($hash));
|
||||
$this->entries[$name] = [$mode, $this->repository->getTree($hash)];
|
||||
} else {
|
||||
$this->entries[$name] = array($mode, new CommitReference($hash));
|
||||
$this->entries[$name] = [$mode, new CommitReference($hash)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ class Tree
|
||||
foreach ($segments as $segment) {
|
||||
if ($element instanceof self) {
|
||||
$element = $element->getEntry($segment);
|
||||
} elseif ($entry instanceof Blob) {
|
||||
} elseif ($element instanceof Blob) {
|
||||
throw new InvalidArgumentException('Unresolvable path');
|
||||
} else {
|
||||
throw new UnexpectedValueException('Unknow type of element');
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git\Util;
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Gitonomy\Git;
|
||||
|
||||
use Gitonomy\Git\Diff\Diff;
|
||||
@@ -34,23 +35,22 @@ class WorkingCopy
|
||||
}
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
{
|
||||
return WorkingStatus::parseOutput();
|
||||
}
|
||||
|
||||
public function getUntrackedFiles()
|
||||
{
|
||||
$lines = explode("\0", $this->run('status', array('--porcelain', '--untracked-files=all', '-z')));
|
||||
$lines = array_filter($lines, function ($l) { return substr($l, 0, 3) === '?? '; });
|
||||
$lines = array_map(function ($l) { return substr($l, 3); }, $lines);
|
||||
$lines = explode("\0", $this->run('status', ['--porcelain', '--untracked-files=all', '-z']));
|
||||
$lines = array_filter($lines, function ($l) {
|
||||
return substr($l, 0, 3) === '?? ';
|
||||
});
|
||||
$lines = array_map(function ($l) {
|
||||
return substr($l, 3);
|
||||
}, $lines);
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
public function getDiffPending()
|
||||
{
|
||||
$diff = Diff::parse($this->run('diff', array('-r', '-p', '-m', '-M', '--full-index')));
|
||||
$diff = Diff::parse($this->run('diff', ['-r', '-p', '-m', '-M', '--full-index']));
|
||||
$diff->setRepository($this->repository);
|
||||
|
||||
return $diff;
|
||||
@@ -58,7 +58,7 @@ class WorkingCopy
|
||||
|
||||
public function getDiffStaged()
|
||||
{
|
||||
$diff = Diff::parse($this->run('diff', array('-r', '-p', '-m', '-M', '--full-index', '--staged')));
|
||||
$diff = Diff::parse($this->run('diff', ['-r', '-p', '-m', '-M', '--full-index', '--staged']));
|
||||
$diff->setRepository($this->repository);
|
||||
|
||||
return $diff;
|
||||
@@ -69,7 +69,7 @@ class WorkingCopy
|
||||
*/
|
||||
public function checkout($revision, $branch = null)
|
||||
{
|
||||
$args = array();
|
||||
$args = [];
|
||||
if ($revision instanceof Commit) {
|
||||
$args[] = $revision->getHash();
|
||||
} elseif ($revision instanceof Reference) {
|
||||
@@ -81,7 +81,7 @@ class WorkingCopy
|
||||
}
|
||||
|
||||
if (null !== $branch) {
|
||||
$args = array_merge($args, array('-b', $branch));
|
||||
$args = array_merge($args, ['-b', $branch]);
|
||||
}
|
||||
|
||||
$this->run('checkout', $args);
|
||||
@@ -89,7 +89,7 @@ class WorkingCopy
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function run($command, array $args = array())
|
||||
protected function run($command, array $args = [])
|
||||
{
|
||||
return $this->repository->run($command, $args);
|
||||
}
|
||||
|
Reference in New Issue
Block a user