Skip to content

Added more type hinting & Fixed bug when parsing renamed files with spaces and/or non english-symbols #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/composer.lock
/phpunit.xml
/vendor
/.idea
4 changes: 1 addition & 3 deletions src/Gitonomy/Git/Blame.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ public function getGroupedLines()
}

/**
* Returns all lines of the blame.
*
* @return array
* @return Line[] All lines of the blame.
*/
public function getLines()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Gitonomy/Git/Blob.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function getHash()
}

/**
* Returns content of the blob.
*
* @throws ProcessException Error occurred while getting content of blob
*
* @return string Content of the blob.
*/
public function getContent()
{
Expand Down
18 changes: 12 additions & 6 deletions src/Gitonomy/Git/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;

/**
Expand All @@ -35,8 +36,8 @@ class Commit extends Revision
/**
* 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 = [])
{
Expand Down Expand Up @@ -91,6 +92,8 @@ public function getShortHash()

/**
* Returns a fixed-with short hash.
*
* @return string Short hash
*/
public function getFixedShortHash($length = 6)
{
Expand All @@ -100,7 +103,7 @@ public function getFixedShortHash($length = 6)
/**
* Returns parent hashes.
*
* @return array An array of SHA1 hashes
* @return string[] An array of SHA1 hashes
*/
public function getParentHashes()
{
Expand All @@ -110,7 +113,7 @@ public function getParentHashes()
/**
* Returns the parent commits.
*
* @return array An array of Commit objects
* @return Commit[] An array of Commit objects
*/
public function getParents()
{
Expand All @@ -132,6 +135,9 @@ public function getTreeHash()
return $this->getData('treeHash');
}

/**
* @return Tree
*/
public function getTree()
{
return $this->getData('tree');
Expand Down Expand Up @@ -184,7 +190,7 @@ public function getShortMessage($length = 50, $preserve = false, $separator = '.
/**
* 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()
{
Expand All @@ -197,7 +203,7 @@ public function resolveReferences()
* @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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Gitonomy/Git/CommitReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

class CommitReference
{
/**
* @var string
*/
private $hash;

public function __construct($hash)
Expand Down
8 changes: 0 additions & 8 deletions src/Gitonomy/Git/Diff/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ public function setRepository(Repository $repository)
}
}

/**
* @return array
*/
public function getRevisions()
{
return $this->revisions;
}

/**
* Get list of files modified in the diff's revision.
*
Expand Down
8 changes: 7 additions & 1 deletion src/Gitonomy/Git/Diff/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class File
protected $isBinary;

/**
* @var array An array of FileChange objects
* @var FileChange[] An array of FileChange objects
*/
protected $changes;

Expand Down Expand Up @@ -215,6 +215,9 @@ public function isBinary()
return $this->isBinary;
}

/**
* @return FileChange[]
*/
public function getChanges()
{
return $this->changes;
Expand All @@ -236,6 +239,9 @@ public function toArray()
];
}

/**
* @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']);
Expand Down
8 changes: 6 additions & 2 deletions src/Gitonomy/Git/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Gitonomy\Git\Exception\InvalidArgumentException;
use Gitonomy\Git\Exception\LogicException;
use RuntimeException;

/**
* Hooks collection, aggregated by repository.
Expand All @@ -23,7 +24,7 @@
class Hooks
{
/**
* @var Gitonomy\Git\Repository
* @var \Gitonomy\Git\Repository
*/
protected $repository;

Expand Down Expand Up @@ -82,7 +83,7 @@ public function setSymlink($name, $file)

$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));
}
}

Expand Down Expand Up @@ -121,6 +122,9 @@ public function remove($name)
unlink($this->getPath($name));
}

/**
* @return string
*/
protected function getPath($name)
{
return $this->repository->getGitDir().'/hooks/'.$name;
Expand Down
6 changes: 5 additions & 1 deletion src/Gitonomy/Git/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Gitonomy\Git;

use Gitonomy\Git\Diff\Diff;
use Gitonomy\Git\Exception\ProcessException;
use Gitonomy\Git\Exception\ReferenceNotFoundException;
use Gitonomy\Git\Util\StringHelper;
Expand Down Expand Up @@ -136,6 +137,9 @@ public function setLimit($limit)
return $this;
}

/**
* @return Commit
*/
public function getSingleCommit()
{
$limit = $this->limit;
Expand All @@ -151,7 +155,7 @@ public function getSingleCommit()
}

/**
* @return array
* @return Commit[]
*/
public function getCommits()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gitonomy/Git/Parser/DiffParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function doParse()

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;
Expand Down
2 changes: 1 addition & 1 deletion src/Gitonomy/Git/Parser/ParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function consumeHash()
protected function consumeRegexp($regexp)
{
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, 30));
throw new RuntimeException('No match for regexp '.$regexp.' Upcoming: '.substr($this->content, $this->cursor, 500));
}

$this->cursor += strlen($vars[0]);
Expand Down
9 changes: 8 additions & 1 deletion src/Gitonomy/Git/PushReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class PushReference
{
const ZERO = '0000000000000000000000000000000000000000';

/**
* @var Repository
*/
protected $repository;
/**
* @var string
*/
Expand Down Expand Up @@ -86,7 +90,7 @@ public function getAfter()
}

/**
* @return array
* @return Log
*/
public function getLog($excludes = [])
{
Expand All @@ -98,6 +102,9 @@ public function getLog($excludes = [])
));
}

/**
* @return string
*/
public function getRevision()
{
if ($this->isDelete()) {
Expand Down
19 changes: 16 additions & 3 deletions src/Gitonomy/Git/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Gitonomy\Git;

use Gitonomy\Git\Exception\ProcessException;
use Gitonomy\Git\Exception\ReferenceNotFoundException;

/**
* Reference in a Git repository.
*
Expand All @@ -29,16 +32,25 @@ public function __construct(Repository $repository, $revision, $commitHash = nul
$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) {
Expand All @@ -55,15 +67,16 @@ public function getCommitHash()
}

/**
* 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);
Expand Down
8 changes: 5 additions & 3 deletions src/Gitonomy/Git/Reference/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/
class Tag extends Reference
{
protected $data;

public function getName()
{
if (!preg_match('#^refs/tags/(.*)$#', $this->revision, $vars)) {
Expand Down Expand Up @@ -65,8 +67,8 @@ public function getCommit()
$parser = new ReferenceParser();
$parser->parse($output);

foreach ($parser->references as $row) {
list($commitHash, $fullname) = $row;
foreach ($parser->references as list($row)) {
$commitHash = $row;
}

return $this->repository->getCommit($commitHash);
Expand Down Expand Up @@ -101,7 +103,7 @@ public function getTaggerEmail()
/**
* Returns the authoring date.
*
* @return DateTime A time object
* @return \DateTime A time object
*/
public function getTaggerDate()
{
Expand Down
Loading