From d5a7ec3cf9fea9006c5057c2b61a1e07d8e2caa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 15 Oct 2026 16:10:53 +0200 Subject: [PATCH] Require gitlib 1.7 and fix its deprecations --- composer.json | 2 +- composer.lock | 22 ++++++++++++---------- resources/config/services.yml | 8 +++++--- spec/Git/GitRepositorySpec.php | 8 +++++--- src/Git/GitRepository.php | 18 ++++++++---------- src/Locator/GitRepositoryLocator.php | 11 ++++------- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 0d145f906..80b01dc2b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "amphp/amp": "^3.0", "amphp/parallel": "^2.1", "doctrine/collections": "^1.6.8 || ^2.0 || ^3.0", - "gitonomy/gitlib": "^1.6", + "gitonomy/gitlib": "^1.7", "laravel/serializable-closure": "^2.0", "monolog/monolog": "^2.0 || ^3.0", "ondram/ci-detector": "^4.0", diff --git a/composer.lock b/composer.lock index efebcae7d..0489f32e9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "65cdb516cf7985eaf6d89dc3432f4d52", + "content-hash": "0b6ae6429cc25f9a4615666a8c0171de", "packages": [ { "name": "amphp/amp", @@ -1003,29 +1003,31 @@ }, { "name": "gitonomy/gitlib", - "version": "v1.6.0", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/gitonomy/gitlib.git", - "reference": "c1476cb0fd317fc512971e926b40ebcdb666e263" + "reference": "02f796eedb1e436429afa1b2730638703480ffa3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/c1476cb0fd317fc512971e926b40ebcdb666e263", - "reference": "c1476cb0fd317fc512971e926b40ebcdb666e263", + "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/02f796eedb1e436429afa1b2730638703480ffa3", + "reference": "02f796eedb1e436429afa1b2730638703480ffa3", "shasum": "" }, "require": { "ext-pcre": "*", - "php": "^8.0", + "php": "^8.1", + "symfony/deprecation-contracts": "^2.5 || ^3", "symfony/polyfill-mbstring": "^1.7", "symfony/process": "^5.4 || ^6.0 || ^7.0 || ^8.0" }, "require-dev": { "ext-fileinfo": "*", - "phpspec/prophecy-phpunit": "^2.0", + "phpspec/prophecy-phpunit": "^2.1", "phpunit/phpunit": "^7.5.20 || ^8.5.20 || ^9.5.9", - "psr/log": "^1.0" + "psr/log": "^1.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0" }, "type": "library", "autoload": { @@ -1062,7 +1064,7 @@ "description": "Library for accessing git", "support": { "issues": "https://github.com/gitonomy/gitlib/issues", - "source": "https://github.com/gitonomy/gitlib/tree/v1.6.0" + "source": "https://github.com/gitonomy/gitlib/tree/v1.7.0" }, "funding": [ { @@ -1070,7 +1072,7 @@ "type": "tidelift" } ], - "time": "2025-12-09T20:06:56+00:00" + "time": "2026-10-15T13:42:18+00:00" }, { "name": "kelunik/certificate", diff --git a/resources/config/services.yml b/resources/config/services.yml index 9efde599f..a8eece855 100644 --- a/resources/config/services.yml +++ b/resources/config/services.yml @@ -31,9 +31,11 @@ services: GrumPHP\Git\GitRepository: arguments: - '@GrumPHP\Locator\GitRepositoryLocator' - - - logger: '@grumphp.logger' - inherit_environment_variables: true + - '@Gitonomy\Git\Driver\Cli\CliDriver' + + Gitonomy\Git\Driver\Cli\CliDriver: + arguments: + $logger: '@grumphp.logger' GrumPHP\IO\IOFactory: arguments: diff --git a/spec/Git/GitRepositorySpec.php b/spec/Git/GitRepositorySpec.php index cce5d6155..5443ca506 100644 --- a/spec/Git/GitRepositorySpec.php +++ b/spec/Git/GitRepositorySpec.php @@ -4,6 +4,7 @@ use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Diff\File; +use Gitonomy\Git\Driver\Cli\CliDriver; use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Repository; use Gitonomy\Git\WorkingCopy; @@ -17,8 +18,9 @@ class GitRepositorySpec extends ObjectBehavior { public function let(GitRepositoryLocator $locator, Repository $repository): void { - $this->beConstructedWith($locator, []); - $locator->locate([])->willReturn($repository); + $driver = new CliDriver(); + $this->beConstructedWith($locator, $driver); + $locator->locate($driver)->willReturn($repository); } function it_is_initializable() @@ -32,7 +34,7 @@ public function it_is_lazy(GitRepositoryLocator $locator, Repository $repository $this->run('command', []); $this->run('command', []); - $locator->locate([])->shouldBeCalledTimes(1); + $locator->locate(Argument::type(CliDriver::class))->shouldBeCalledTimes(1); } public function it_can_run_commands(Repository $repository): void diff --git a/src/Git/GitRepository.php b/src/Git/GitRepository.php index fb05b031d..3aa702035 100644 --- a/src/Git/GitRepository.php +++ b/src/Git/GitRepository.php @@ -5,6 +5,7 @@ namespace GrumPHP\Git; use Gitonomy\Git\Diff\Diff; +use Gitonomy\Git\Driver\Cli\CliDriver; use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Repository; use Gitonomy\Git\WorkingCopy; @@ -23,19 +24,19 @@ class GitRepository private $repositoryLocator; /** - * @var array + * @var CliDriver */ - private $repositoryOptions; + private $driver; /** * @var ?Repository */ private $repository; - public function __construct(GitRepositoryLocator $repositoryLocator, array $repositoryOptions) + public function __construct(GitRepositoryLocator $repositoryLocator, CliDriver $driver) { $this->repositoryLocator = $repositoryLocator; - $this->repositoryOptions = $repositoryOptions; + $this->driver = $driver; } public function getWorkingCopy(): WorkingCopy @@ -49,7 +50,7 @@ public function run(string $command, array $args): ?string } /** - * The gitonomy run method handles errors differently based on debug (throw) or non-debug (return null) mode. + * The gitonomy run method throws a ProcessException when the git command fails. * This method makes it possible to run a git command but fallback to a default string if the command fails. * It can be used to e.g. fetch git configurations. */ @@ -66,10 +67,7 @@ public function tryToRunWithFallback(callable $run, string $fallback): string public function createRawDiff(string $rawDiff): Diff { - $diff = Diff::parse($rawDiff); - $diff->setRepository($this->getRepository()); - - return $diff; + return Diff::parse($rawDiff, $this->getRepository()); } /** @@ -80,7 +78,7 @@ public function createRawDiff(string $rawDiff): Diff private function getRepository(): Repository { if (!$this->repository) { - $this->repository = $this->repositoryLocator->locate($this->repositoryOptions); + $this->repository = $this->repositoryLocator->locate($this->driver); } return $this->repository; diff --git a/src/Locator/GitRepositoryLocator.php b/src/Locator/GitRepositoryLocator.php index 1662632eb..80330d7e6 100644 --- a/src/Locator/GitRepositoryLocator.php +++ b/src/Locator/GitRepositoryLocator.php @@ -4,6 +4,7 @@ namespace GrumPHP\Locator; +use Gitonomy\Git\Driver\Cli\CliDriver; use Gitonomy\Git\Repository; use GrumPHP\Util\Paths; @@ -19,16 +20,12 @@ public function __construct(Paths $paths) $this->paths = $paths; } - public function locate(array $options): Repository + public function locate(CliDriver $driver): Repository { return new Repository( $this->paths->getGitWorktreeDir(), - array_merge( - [ - 'working_dir' => $this->paths->getGitWorkingDir(), - ], - $options - ) + $this->paths->getGitWorkingDir(), + $driver ); } }