mirror of
https://github.com/pestphp/pest.git
synced 2026-07-24 10:30:03 +02:00
chore: fixes tia when not running on root
This commit is contained in:
@@ -9,6 +9,7 @@ use Pest\Contracts\Plugins\AddsOutput;
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Contracts\Plugins\Terminable;
|
||||
use Pest\Exceptions\NoAffectedTestsFound;
|
||||
use Pest\Exceptions\TiaRequiresRepositoryRoot;
|
||||
use Pest\Panic;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
use Pest\Plugins\Tia\BaselineSync;
|
||||
@@ -627,6 +628,13 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
||||
private function handleParent(array $arguments, string $projectRoot, bool $forceRebuild): array
|
||||
{
|
||||
$this->watchPatterns->useDefaults($projectRoot);
|
||||
|
||||
$subdirectoryPrefix = $this->gitSubdirectoryPrefix($projectRoot);
|
||||
|
||||
if ($subdirectoryPrefix !== null) {
|
||||
Panic::with(new TiaRequiresRepositoryRoot($subdirectoryPrefix));
|
||||
}
|
||||
|
||||
$this->branch = new ChangedFiles($projectRoot)->currentBranch() ?? 'main';
|
||||
|
||||
$fingerprint = Fingerprint::compute($projectRoot);
|
||||
@@ -1643,6 +1651,27 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
||||
return implode(', ', array_keys($seen));
|
||||
}
|
||||
|
||||
/**
|
||||
* The path from the git repository root down to $projectRoot (e.g.
|
||||
* `laravel-app`) when the project is nested inside a larger repo, or `null`
|
||||
* when the project root is itself the repo root (or git is unavailable).
|
||||
* TIA requires the two to coincide: git reports and addresses paths
|
||||
* relative to the repo root, while the dependency graph is project-relative.
|
||||
*/
|
||||
private function gitSubdirectoryPrefix(string $projectRoot): ?string
|
||||
{
|
||||
$process = new Process(['git', 'rev-parse', '--show-prefix'], $projectRoot);
|
||||
$process->run();
|
||||
|
||||
if (! $process->isSuccessful()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$prefix = trim($process->getOutput());
|
||||
|
||||
return $prefix === '' ? null : rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $prefix), '/');
|
||||
}
|
||||
|
||||
private function composerLockDelta(string $projectRoot, string $sha): string
|
||||
{
|
||||
$current = @file_get_contents($projectRoot.'/composer.lock');
|
||||
|
||||
Reference in New Issue
Block a user