Skip to content

fix: support Tia when the Pest project is a subdirectory of the git repository - #1805

Draft
johnbacon wants to merge 1 commit into
pestphp:5.xfrom
johnbacon:fix/tia-monorepo-subdirectory
Draft

fix: support Tia when the Pest project is a subdirectory of the git repository#1805
johnbacon wants to merge 1 commit into
pestphp:5.xfrom
johnbacon:fix/tia-monorepo-subdirectory

Conversation

@johnbacon

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

Tia currently cannot be used when the Pest project is a subdirectory of its git repository (e.g. a backend/ Laravel app in a monorepo). On 4.x this failed silently — change detection mapped every change to zero tests and replayed stale results as passing (#1783's reproduction) — and 5.x added the TiaRequiresRepositoryRoot guard, which refuses to run instead (#1802).

The root cause is a path-frame mismatch: git prints and addresses paths relative to the repository root, while the Tia dependency graph is keyed on project-relative paths. This PR makes ChangedFiles translate at every git boundary instead of requiring the two roots to coincide:

  • ChangedFiles::gitPrefix() resolves the project's prefix inside the repository once, via git rev-parse --show-prefix (empty at the repo root or when git is unavailable, so single-repo projects are byte-for-byte unaffected).
  • Output paths from git diff --name-only and git status --porcelain are stripped to project-relative; paths outside the project (sibling packages) are dropped.
  • Input paths to git show <sha>:<path> (behaviourally-unchanged filtering, and the composer.lock drift summary in the Tia plugin) get the prefix prepended.
  • git check-ignore --stdin already receives cwd-relative paths with the project root as cwd, so it needed no change.
  • The TiaRequiresRepositoryRoot guard and exception are removed — with the translation in place there is nothing left to guard against. The suggested-fix sketch in TIA: change detection misses all changes when the Pest project is a subdirectory of the git repository (monorepo) #1783 is what's implemented here.

Covered by new ChangedFiles unit tests that build real nested-repo fixtures: prefix resolution, working-tree + committed change detection from a subdirectory (sibling changes dropped), the behaviourally-unchanged filter across the prefix boundary, and a repo-root regression case. Full suite (--exclude-group=integration), Pint, Rector, and PHPStan are green locally.

One adjacent gap deliberately not touched here: BaselineSync reads <projectRoot>/.git/config directly to derive the GitHub slug, so remote baseline sync stays inactive for subdirectory projects (and git worktrees, where .git is a file). Switching that to git config --get remote.origin.url would fix both — happy to follow up separately if you want it.

Related:

🤖 Generated with Claude Code

…epository

Git prints and addresses paths relative to the repository root, while
Tia's dependency graph is keyed on project-relative paths. When the two
roots coincide the notions are identical; in a monorepo they are not,
which previously made change detection map every change to zero tests —
so the repository-root guard refused to run Tia at all.

ChangedFiles now resolves the project's prefix inside the repository
once (git rev-parse --show-prefix) and translates at every git
boundary: output paths from diff/status are stripped to project-relative
(dropping sibling packages), and input paths to git show are prefixed.
The guard and its exception are removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TIA: change detection misses all changes when the Pest project is a subdirectory of the git repository (monorepo)

1 participant