Skip to content
Open
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
44 changes: 0 additions & 44 deletions src/Exceptions/TiaRequiresRepositoryRoot.php

This file was deleted.

54 changes: 31 additions & 23 deletions src/Plugins/Tia.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Pest\Exceptions\TiaRequiresCommit;
use Pest\Exceptions\TiaRequiresDefaultBranch;
use Pest\Exceptions\TiaRequiresRemote;
use Pest\Exceptions\TiaRequiresRepositoryRoot;
use Pest\Panic;
use Pest\Plugins\Concerns\HandleArguments;
use Pest\Plugins\Tia\BaselineSync;
Expand Down Expand Up @@ -357,8 +356,6 @@ private static function applyWatchPatternMarks(array $arguments, WatchPatterns $
}

/**
* Mirrors {@see HandleArguments::hasArgument()} for
*
* @param array<int, string> $arguments
*/
private static function argumentPresent(string $argument, array $arguments): bool
Expand Down Expand Up @@ -440,17 +437,11 @@ public function getAssertionCount(string $testId): int
return $this->cachedAssertionsByTestId[$testId] ?? 0;
}

/**
* {@inheritDoc}
*/
public function handleOriginalArguments(array $arguments): void
{
$this->originalArguments = $arguments;
}

/**
* {@inheritDoc}
*/
public function handleArguments(array $arguments): array
{
if ($this->hasArgument(self::BASELINE_PATH_OPTION, $arguments)) {
Expand Down Expand Up @@ -816,12 +807,6 @@ private function handleParent(array $arguments, string $projectRoot, bool $force
{
$this->watchPatterns->useDefaults($projectRoot);

$subdirectoryPrefix = $this->gitSubdirectoryPrefix($projectRoot);

if ($subdirectoryPrefix !== null) {
Panic::with(new TiaRequiresRepositoryRoot($subdirectoryPrefix));
}

try {
$this->resolveBranch($projectRoot);
} catch (MissingDependency $missingGit) {
Expand Down Expand Up @@ -1052,6 +1037,8 @@ private function enterReplayMode(Graph $graph, string $projectRoot, array $argum
$branchSha = $graph->recordedAtSha($this->branch);
$changed = $changedFiles->since($branchSha) ?? [];

$outsideProject = $changedFiles->outsideProject();

$changed = $changedFiles->filterUnchangedSinceLastRun(
$changed,
$graph->lastRunTree($this->branch),
Expand Down Expand Up @@ -1089,7 +1076,7 @@ private function enterReplayMode(Graph $graph, string $projectRoot, array $argum
...$rerunFromCache,
]));

$this->reportAffectedSummary($changed, $affectedFromChanges, $rerunFromCache, $affected);
$this->reportAffectedSummary($changed, $affectedFromChanges, $rerunFromCache, $affected, $outsideProject);

$affectedSet = array_fill_keys($affected, true);
$canRefreshReplayEdges = $affected !== [] && $coverageAvailable;
Expand Down Expand Up @@ -1154,13 +1141,15 @@ private function enterReplayMode(Graph $graph, string $projectRoot, array $argum
* @param array<int, string> $affectedFromChanges
* @param array<int, string> $rerunFromCache
* @param array<int, string> $affected
* @param array<int, string> $outsideProject
*/
private function reportAffectedSummary(array $changedFiles, array $affectedFromChanges, array $rerunFromCache, array $affected): void
private function reportAffectedSummary(array $changedFiles, array $affectedFromChanges, array $rerunFromCache, array $affected, array $outsideProject = []): void
{
$this->output->writeln('');

if ($affected === []) {
$this->renderChild('Experimental TIA mode enabled.');
$this->reportChangesOutsideProject($outsideProject);

return;
}
Expand Down Expand Up @@ -1223,6 +1212,27 @@ private function reportAffectedSummary(array $changedFiles, array $affectedFromC
if ($remainder > 0) {
$this->output->writeln(sprintf(' <fg=gray>… +%d more</>', $remainder));
}

$this->reportChangesOutsideProject($outsideProject);
}

/**
* @param array<int, string> $outsideProject Repository-relative paths.
*/
private function reportChangesOutsideProject(array $outsideProject): void
{
if ($outsideProject === []) {
return;
}

$count = count($outsideProject);

$this->renderChild(sprintf(
'%d changed file%s outside this project %s ignored — TIA only tracks files under the project root.',
$count,
$count === 1 ? '' : 's',
$count === 1 ? 'was' : 'were',
));
}

/**
Expand Down Expand Up @@ -2178,6 +2188,7 @@ private function formatStructuralDrift(array $drift): string
'js_config' => 'JS/TS config',
'pest_factory' => 'Pest internals',
'pest_method_factory' => 'Pest internals',
'project_prefix' => 'project location in the repository',
];

$seen = [];
Expand All @@ -2192,19 +2203,16 @@ private function formatStructuralDrift(array $drift): string
return implode(', ', array_keys($seen));
}

private function gitSubdirectoryPrefix(string $projectRoot): ?string
{
return new Git($projectRoot)->subdirectoryPrefix();
}

private function composerLockDelta(string $projectRoot, string $sha): string
{
$current = @file_get_contents($projectRoot.'/composer.lock');
if ($current === false) {
return '';
}

$baseline = new Git($projectRoot)->show($sha, 'composer.lock');
$git = new Git($projectRoot);

$baseline = $git->show($sha, $git->pathPrefix().'composer.lock');

if ($baseline === null) {
return '';
Expand Down
19 changes: 2 additions & 17 deletions src/Plugins/Tia/Baselines/BaseRemote.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Pest\Plugins\Tia\Baselines;

use Pest\Plugins\Tia\WatchPatterns;
use Pest\Support\Git;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -73,23 +74,7 @@ public function classifyError(string $output): array

protected function readOriginUrl(string $projectRoot): ?string // @pest-arch-ignore-line
{
$gitConfig = $projectRoot.DIRECTORY_SEPARATOR.'.git'.DIRECTORY_SEPARATOR.'config';

if (! is_file($gitConfig)) {
return null;
}

$content = @file_get_contents($gitConfig);

if ($content === false) {
return null;
}

if (preg_match('/\[remote "origin"\][^\[]*?url\s*=\s*(\S+)/s', $content, $match) !== 1) {
return null;
}

return $match[1];
return new Git($projectRoot)->originUrl();
}

/**
Expand Down
Loading