From 565526a58db0e0a54aab7f15ac714586ad4511bb Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 14:54:28 +0200 Subject: [PATCH 01/16] changed repo name in the composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 417c763..2e64fac 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "gitonomy/gitlib", + "name": "tolik518/gitlib", "description": "Library for accessing git", "license": "MIT", "authors": [ From 61c82649ab79a65e435525197eafaa4e3f88650b Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 16:05:16 +0200 Subject: [PATCH 02/16] added path to the symlink RuntimeException exception-message --- src/Gitonomy/Git/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index 3c19d2c..847732d 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -82,7 +82,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)); } } From 2eb7da09c1dca282b13c731a33df3656bfd0acf8 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 18:50:07 +0200 Subject: [PATCH 03/16] added more and better typehints into PHPDocs above methods --- src/Gitonomy/Git/Blame.php | 4 +-- src/Gitonomy/Git/Blob.php | 3 +- src/Gitonomy/Git/Commit.php | 18 ++++++---- src/Gitonomy/Git/CommitReference.php | 3 ++ src/Gitonomy/Git/Hooks.php | 6 +++- src/Gitonomy/Git/Log.php | 6 +++- src/Gitonomy/Git/PushReference.php | 10 +++++- src/Gitonomy/Git/Reference.php | 21 ++++++++--- src/Gitonomy/Git/ReferenceBag.php | 52 +++++++++++++++++----------- src/Gitonomy/Git/Repository.php | 3 ++ src/Gitonomy/Git/RevisionList.php | 3 ++ 11 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index a9667cb..dec0773 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -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() { diff --git a/src/Gitonomy/Git/Blob.php b/src/Gitonomy/Git/Blob.php index 1015093..eadc140 100644 --- a/src/Gitonomy/Git/Blob.php +++ b/src/Gitonomy/Git/Blob.php @@ -58,9 +58,8 @@ 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() { diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 10141be..2008f7a 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -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; /** @@ -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 = []) { @@ -91,6 +92,8 @@ public function getShortHash() /** * Returns a fixed-with short hash. + * + * @return string Short hash */ public function getFixedShortHash($length = 6) { @@ -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() { @@ -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() { @@ -132,6 +135,9 @@ public function getTreeHash() return $this->getData('treeHash'); } + /** + * @return Tree + */ public function getTree() { return $this->getData('tree'); @@ -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() { @@ -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) { diff --git a/src/Gitonomy/Git/CommitReference.php b/src/Gitonomy/Git/CommitReference.php index bb20bc3..b7c1730 100644 --- a/src/Gitonomy/Git/CommitReference.php +++ b/src/Gitonomy/Git/CommitReference.php @@ -14,6 +14,9 @@ class CommitReference { + /** + * @var string $hash + */ private $hash; public function __construct($hash) diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index 847732d..2815799 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -14,6 +14,7 @@ use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Exception\LogicException; +use RuntimeException; /** * Hooks collection, aggregated by repository. @@ -23,7 +24,7 @@ class Hooks { /** - * @var Gitonomy\Git\Repository + * @var \Gitonomy\Git\Repository */ protected $repository; @@ -121,6 +122,9 @@ public function remove($name) unlink($this->getPath($name)); } + /** + * @return string + */ protected function getPath($name) { return $this->repository->getGitDir().'/hooks/'.$name; diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 84b8bca..4766535 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -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; @@ -136,6 +137,9 @@ public function setLimit($limit) return $this; } + /** + * @return Commit + */ public function getSingleCommit() { $limit = $this->limit; @@ -151,7 +155,7 @@ public function getSingleCommit() } /** - * @return array + * @return Commit[] */ public function getCommits() { diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index 3911bd2..b6953db 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -24,6 +24,11 @@ class PushReference { const ZERO = '0000000000000000000000000000000000000000'; + + /** + * @var Repository + */ + protected $repository; /** * @var string */ @@ -86,7 +91,7 @@ public function getAfter() } /** - * @return array + * @return Log */ public function getLog($excludes = []) { @@ -98,6 +103,9 @@ public function getLog($excludes = []) )); } + /** + * @return string + */ public function getRevision() { if ($this->isDelete()) { diff --git a/src/Gitonomy/Git/Reference.php b/src/Gitonomy/Git/Reference.php index 23f1cb7..7f14a75 100644 --- a/src/Gitonomy/Git/Reference.php +++ b/src/Gitonomy/Git/Reference.php @@ -12,6 +12,9 @@ namespace Gitonomy\Git; +use Gitonomy\Git\Exception\ProcessException; +use Gitonomy\Git\Exception\ReferenceNotFoundException; + /** * Reference in a Git repository. * @@ -22,23 +25,32 @@ abstract class Reference extends Revision { protected $commitHash; - public function __construct(Repository $repository, $revision, $commitHash = null) + public function __construct(Repository $repository, $revision, $commitHash = null) { $this->repository = $repository; $this->revision = $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) { @@ -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); diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index 35fd710..a9f90c5 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -29,7 +29,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate /** * Repository object. * - * @var Gitonomy\Git\Repository + * @var Repository */ protected $repository; @@ -43,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; @@ -64,7 +64,7 @@ class ReferenceBag implements \Countable, \IteratorAggregate /** * Constructor. * - * @param Gitonomy\Git\Repository $repository The repository + * @param Repository $repository The repository */ public function __construct($repository) { @@ -92,6 +92,9 @@ public function get($fullname) return $this->references[$fullname]; } + /** + * @return bool + */ public function has($fullname) { $this->initialize(); @@ -99,6 +102,9 @@ public function has($fullname) return isset($this->references[$fullname]); } + /** + * @return Reference + */ public function update(Reference $reference) { $fullname = $reference->getFullname(); @@ -111,6 +117,9 @@ public function update(Reference $reference) return $reference; } + /** + * @return Reference + */ public function createBranch($name, $commitHash) { $branch = new Branch($this->repository, 'refs/heads/'.$name, $commitHash); @@ -118,6 +127,9 @@ public function createBranch($name, $commitHash) return $this->update($branch); } + /** + * @return Reference + */ public function createTag($name, $commitHash) { $tag = new Tag($this->repository, 'refs/tags/'.$name, $commitHash); @@ -125,6 +137,9 @@ public function createTag($name, $commitHash) return $this->update($tag); } + /** + * @return void + */ public function delete($fullname) { $this->repository->run('update-ref', ['-d', $fullname]); @@ -132,6 +147,9 @@ public function delete($fullname) unset($this->references[$fullname]); } + /** + * @return bool + */ public function hasBranches() { $this->initialize(); @@ -154,16 +172,18 @@ public function hasTag($name) return $this->has('refs/tags/'.$name); } + /** + * @return Branch + */ public function getFirstBranch() { $this->initialize(); reset($this->branches); - return current($this->references); } /** - * @return array An array of Tag objects + * @return Tag[] An array of Tag objects */ public function resolveTags($hash) { @@ -184,7 +204,7 @@ public function resolveTags($hash) } /** - * @return array An array of Branch objects + * @return Branch[] An array of Branch objects */ public function resolveBranches($hash) { @@ -205,7 +225,7 @@ public function resolveBranches($hash) } /** - * @return array An array of references + * @return Reference[] An array of references */ public function resolve($hash) { @@ -226,9 +246,7 @@ public function resolve($hash) } /** - * Returns all tags. - * - * @return array + * @return Tag[] All tags. */ public function getTags() { @@ -238,9 +256,7 @@ public function getTags() } /** - * Returns all branches. - * - * @return array + * @return Branch[] All branches. */ public function getBranches() { @@ -257,9 +273,7 @@ public function getBranches() } /** - * Returns all locales branches. - * - * @return array + * @return Branch[] All local branches. */ public function getLocalBranches() { @@ -274,9 +288,7 @@ public function getLocalBranches() } /** - * Returns all remote branches. - * - * @return array + * @return Branch[] All remote branches. */ public function getRemoteBranches() { diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index 3920616..fe77a88 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -376,6 +376,9 @@ public function getBlob($hash) return $this->objects[$hash]; } + /** + * @return Blame + */ public function getBlame($revision, $file, $lineRange = null) { if (is_string($revision)) { diff --git a/src/Gitonomy/Git/RevisionList.php b/src/Gitonomy/Git/RevisionList.php index a3dfe59..1c1a1dc 100644 --- a/src/Gitonomy/Git/RevisionList.php +++ b/src/Gitonomy/Git/RevisionList.php @@ -49,6 +49,9 @@ public function __construct(Repository $repository, $revisions) $this->revisions = $revisions; } + /** + * @return Revision[] + */ public function getAll() { return $this->revisions; From 5b1e660443b90bac98d114fe40c8f497568868ba Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 20:52:56 +0200 Subject: [PATCH 04/16] Regex didn't count for the rare case when the diff has quotation marks around the filenames (file names with non-english symbols for example) --- src/Gitonomy/Git/Parser/DiffParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gitonomy/Git/Parser/DiffParser.php b/src/Gitonomy/Git/Parser/DiffParser.php index 3fa9e2e..fa566f8 100644 --- a/src/Gitonomy/Git/Parser/DiffParser.php +++ b/src/Gitonomy/Git/Parser/DiffParser.php @@ -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; From 469c47c303309c914b125f2413189909054ccb08 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 20:54:36 +0200 Subject: [PATCH 05/16] replaced uninitialized $entry variable with $element --- src/Gitonomy/Git/Tree.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index d317983..570c8ff 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -96,7 +96,7 @@ public function resolvePath($path) 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'); From 0b56aaba0bb59174dd99c0326451ea231a147497 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 21:17:16 +0200 Subject: [PATCH 06/16] removed getRevisions() since revisions isn't a part of the Diff object --- src/Gitonomy/Git/Diff/Diff.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Gitonomy/Git/Diff/Diff.php b/src/Gitonomy/Git/Diff/Diff.php index faafbcb..4868826 100644 --- a/src/Gitonomy/Git/Diff/Diff.php +++ b/src/Gitonomy/Git/Diff/Diff.php @@ -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. * From 85866d578e707c2e5f42625c257069417a5732e6 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 21:28:25 +0200 Subject: [PATCH 07/16] removed unused $fullname in the getCommit() method --- src/Gitonomy/Git/Reference/Tag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index 988ac1e..f5fdd07 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -65,8 +65,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); From 112dea50e147e510b7ddfd5ae73c0716ac91320a Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 21:40:03 +0200 Subject: [PATCH 08/16] - added more type hinting - introduced data property to Tag - added .idea to .gitignore --- .gitignore | 1 + src/Gitonomy/Git/Diff/File.php | 8 +++++++- src/Gitonomy/Git/Reference/Tag.php | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 376a2cd..065135a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /composer.lock /phpunit.xml /vendor +/.idea \ No newline at end of file diff --git a/src/Gitonomy/Git/Diff/File.php b/src/Gitonomy/Git/Diff/File.php index f709976..d3da24b 100644 --- a/src/Gitonomy/Git/Diff/File.php +++ b/src/Gitonomy/Git/Diff/File.php @@ -55,7 +55,7 @@ class File protected $isBinary; /** - * @var array An array of FileChange objects + * @var FileChange[] An array of FileChange objects */ protected $changes; @@ -215,6 +215,9 @@ public function isBinary() return $this->isBinary; } + /** + * @return FileChange[] + */ public function getChanges() { return $this->changes; @@ -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']); diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index f5fdd07..bca6ca4 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -27,6 +27,8 @@ */ class Tag extends Reference { + protected $data; + public function getName() { if (!preg_match('#^refs/tags/(.*)$#', $this->revision, $vars)) { @@ -101,7 +103,7 @@ public function getTaggerEmail() /** * Returns the authoring date. * - * @return DateTime A time object + * @return \DateTime A time object */ public function getTaggerDate() { From 4e183359a8361fa768bcf4b6024c0655592bbfb5 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Wed, 3 Aug 2022 22:02:28 +0200 Subject: [PATCH 09/16] - changes that were requested by " continuous-integration/styleci/pr" - fixed composer.json --- composer.json | 2 +- src/Gitonomy/Git/Blob.php | 1 + src/Gitonomy/Git/CommitReference.php | 2 +- src/Gitonomy/Git/PushReference.php | 1 - src/Gitonomy/Git/Reference.php | 2 +- src/Gitonomy/Git/ReferenceBag.php | 1 + 6 files changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2e64fac..417c763 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "tolik518/gitlib", + "name": "gitonomy/gitlib", "description": "Library for accessing git", "license": "MIT", "authors": [ diff --git a/src/Gitonomy/Git/Blob.php b/src/Gitonomy/Git/Blob.php index eadc140..e455fe2 100644 --- a/src/Gitonomy/Git/Blob.php +++ b/src/Gitonomy/Git/Blob.php @@ -59,6 +59,7 @@ public function getHash() /** * @throws ProcessException Error occurred while getting content of blob + * * @return string Content of the blob. */ public function getContent() diff --git a/src/Gitonomy/Git/CommitReference.php b/src/Gitonomy/Git/CommitReference.php index b7c1730..7be3d89 100644 --- a/src/Gitonomy/Git/CommitReference.php +++ b/src/Gitonomy/Git/CommitReference.php @@ -15,7 +15,7 @@ class CommitReference { /** - * @var string $hash + * @var string */ private $hash; diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index b6953db..dea1082 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -24,7 +24,6 @@ class PushReference { const ZERO = '0000000000000000000000000000000000000000'; - /** * @var Repository */ diff --git a/src/Gitonomy/Git/Reference.php b/src/Gitonomy/Git/Reference.php index 7f14a75..96b8fa1 100644 --- a/src/Gitonomy/Git/Reference.php +++ b/src/Gitonomy/Git/Reference.php @@ -25,7 +25,7 @@ abstract class Reference extends Revision { protected $commitHash; - public function __construct(Repository $repository, $revision, $commitHash = null) + public function __construct(Repository $repository, $revision, $commitHash = null) { $this->repository = $repository; $this->revision = $revision; diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index a9f90c5..4b79fc6 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -179,6 +179,7 @@ public function getFirstBranch() { $this->initialize(); reset($this->branches); + return current($this->references); } From 639d6915f9f90ab4dd9de334b527f411abc67af1 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Thu, 4 Aug 2022 08:45:29 +0200 Subject: [PATCH 10/16] upped the number of characters that are shown to get a more verbose exception --- src/Gitonomy/Git/Parser/ParserBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gitonomy/Git/Parser/ParserBase.php b/src/Gitonomy/Git/Parser/ParserBase.php index 7ce1eae..7cd37e7 100644 --- a/src/Gitonomy/Git/Parser/ParserBase.php +++ b/src/Gitonomy/Git/Parser/ParserBase.php @@ -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]); From 0db385ac9fd07f2998508b9bec489a70e1fca776 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Thu, 4 Aug 2022 08:57:45 +0200 Subject: [PATCH 11/16] added type annotation for file in the Diff class --- src/Gitonomy/Git/Diff/Diff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gitonomy/Git/Diff/Diff.php b/src/Gitonomy/Git/Diff/Diff.php index 4868826..7737ee8 100644 --- a/src/Gitonomy/Git/Diff/Diff.php +++ b/src/Gitonomy/Git/Diff/Diff.php @@ -23,7 +23,7 @@ class Diff { /** - * @var array + * @var File[] */ protected $files; @@ -65,7 +65,7 @@ public function setRepository(Repository $repository) /** * 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() { From 462989ef179c5ba0933e71d9144ea948c3f30b8c Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 5 Aug 2022 09:31:06 +0200 Subject: [PATCH 12/16] - fixed parser to properly work with files - with umlauts added a test - made changes @lyrixx suggested --- .gitignore | 3 +-- src/Gitonomy/Git/Hooks.php | 4 ++-- src/Gitonomy/Git/Parser/DiffParser.php | 10 ++++++---- tests/Gitonomy/Git/Tests/DiffTest.php | 10 ++++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 065135a..5124f36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /.phpunit.result.cache /composer.lock /phpunit.xml -/vendor -/.idea \ No newline at end of file +/vendor \ No newline at end of file diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index 2815799..3f4ce8f 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -14,7 +14,7 @@ use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Exception\LogicException; -use RuntimeException; +use Gitonomy\Git\Exception\RuntimeException; /** * Hooks collection, aggregated by repository. @@ -29,7 +29,7 @@ class Hooks protected $repository; /** - * @var Repository + * @var Repository $repository */ public function __construct(Repository $repository) { diff --git a/src/Gitonomy/Git/Parser/DiffParser.php b/src/Gitonomy/Git/Parser/DiffParser.php index fa566f8..113517e 100644 --- a/src/Gitonomy/Git/Parser/DiffParser.php +++ b/src/Gitonomy/Git/Parser/DiffParser.php @@ -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; @@ -74,14 +74,15 @@ protected function doParse() } $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]; @@ -90,6 +91,7 @@ protected function doParse() $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; diff --git a/tests/Gitonomy/Git/Tests/DiffTest.php b/tests/Gitonomy/Git/Tests/DiffTest.php index 08f2e94..e251d72 100644 --- a/tests/Gitonomy/Git/Tests/DiffTest.php +++ b/tests/Gitonomy/Git/Tests/DiffTest.php @@ -20,6 +20,7 @@ class DiffTest extends AbstractTest const CREATE_COMMIT = 'e6fa3c792facc06faa049a6938c84c411954deb5'; const RENAME_COMMIT = '6640e0ef31518054847a1876328e26ee64083e0a'; const CHANGEMODE_COMMIT = '93da965f58170f13017477b9a608657e87e23230'; + const FILE_WITH_UMLAUTS_COMMIT = '8defb9217692dc1f4c18e05e343ca91cf5047702'; /** * @dataProvider provideFoobar @@ -140,4 +141,13 @@ public function testDiffRangeParse($repository) $this->assertSame(1, $changes[0]->getRangeNewStart()); $this->assertSame(0, $changes[0]->getRangeNewCount()); } + + /** + * @dataProvider provideFoobar + */ + public function testWorksWithUmlauts($repository) + { + $files = $repository->getCommit(self::FILE_WITH_UMLAUTS_COMMIT)->getDiff()->getFiles(); + $this->assertSame('file_with_umlauts_\303\244\303\266\303\274', $files[0]->getNewName()); + } } From 3316ceca7619d1a2cc726ef2da485ccaf45cd74d Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 5 Aug 2022 09:34:31 +0200 Subject: [PATCH 13/16] - made fixes for @continuous-integration/styleci/pr --- src/Gitonomy/Git/Hooks.php | 2 +- src/Gitonomy/Git/Parser/DiffParser.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index 3f4ce8f..dd0adbe 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -29,7 +29,7 @@ class Hooks protected $repository; /** - * @var Repository $repository + * @var Repository */ public function __construct(Repository $repository) { diff --git a/src/Gitonomy/Git/Parser/DiffParser.php b/src/Gitonomy/Git/Parser/DiffParser.php index 113517e..3983e34 100644 --- a/src/Gitonomy/Git/Parser/DiffParser.php +++ b/src/Gitonomy/Git/Parser/DiffParser.php @@ -76,10 +76,10 @@ protected function doParse() //verifying if the file was deleted or created if ($this->expects('--- ')) { - $oldName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $oldName ; + $oldName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $oldName; $this->consumeNewLine(); $this->consume('+++ '); - $newName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $newName ; + $newName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $newName; $this->consumeNewLine(); } elseif ($this->expects('Binary files ')) { $vars = $this->consumeRegexp('/"?(.*?)"? and "?(.*?)"? differ\n/'); From 5c6adcdc2135dfdde5696da578d09afe149dd003 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 5 Aug 2022 10:06:54 +0200 Subject: [PATCH 14/16] - made one more fix for @continuous-integration/styleci/pr --- src/Gitonomy/Git/Parser/DiffParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gitonomy/Git/Parser/DiffParser.php b/src/Gitonomy/Git/Parser/DiffParser.php index 3983e34..6cec80a 100644 --- a/src/Gitonomy/Git/Parser/DiffParser.php +++ b/src/Gitonomy/Git/Parser/DiffParser.php @@ -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; From f396c08f3df14c14354be505c3f23595f5640cdf Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 5 Aug 2022 10:08:15 +0200 Subject: [PATCH 15/16] - switches quotes for @continuous-integration/styleci/pr --- src/Gitonomy/Git/Parser/DiffParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gitonomy/Git/Parser/DiffParser.php b/src/Gitonomy/Git/Parser/DiffParser.php index 6cec80a..e14f879 100644 --- a/src/Gitonomy/Git/Parser/DiffParser.php +++ b/src/Gitonomy/Git/Parser/DiffParser.php @@ -76,10 +76,10 @@ protected function doParse() //verifying if the file was deleted or created if ($this->expects('--- ')) { - $oldName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $oldName; + $oldName = $this->consumeTo("\n") === '/dev/null' ? '/dev/null' : $oldName; $this->consumeNewLine(); $this->consume('+++ '); - $newName = $this->consumeTo("\n") === "/dev/null" ? '/dev/null' : $newName; + $newName = $this->consumeTo("\n") === '/dev/null' ? '/dev/null' : $newName; $this->consumeNewLine(); } elseif ($this->expects('Binary files ')) { $vars = $this->consumeRegexp('/"?(.*?)"? and "?(.*?)"? differ\n/'); From 94802aeadad748eff1d7b1022ba82e041e27f0f4 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 5 Aug 2022 11:02:03 +0200 Subject: [PATCH 16/16] added trailing \n to the gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5124f36..376a2cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /.phpunit.result.cache /composer.lock /phpunit.xml -/vendor \ No newline at end of file +/vendor