Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 12 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions spec/Git/GitRepositorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/Git/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.
*/
Expand All @@ -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());
}

/**
Expand All @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions src/Locator/GitRepositoryLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GrumPHP\Locator;

use Gitonomy\Git\Driver\Cli\CliDriver;
use Gitonomy\Git\Repository;
use GrumPHP\Util\Paths;

Expand All @@ -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
);
}
}
Loading