Repository navigation
feat(tia): support projects in git repository subdirectories (monorepos) - #1809
Closed
einar-hansen wants to merge 6 commits into
Closed
einar-hansen wants to merge 6 commits into
einar-hansen wants to merge 6 commits into
Conversation
Tia previously refused to run when the project root was not the git repository root, telling monorepo users to "give the project its own git repository". The underlying problem was a path-space mismatch: git's plumbing (status --porcelain, diff --name-only, show SHA:path) speaks repository-root-relative paths, while the dependency graph, watch patterns and coverage edges all speak project-root-relative paths. ChangedFiles now detects the project's location inside the repository once (git rev-parse --show-prefix) and translates at every git boundary: - status/diff output is mapped to project-relative paths, and paths outside the project subtree are dropped — they are as invisible to the project's graph as files outside the repository are for a root-level project, and leaking them through would hit the unknown-file catch-all and force a full rerun on every sibling-project change; - the diff listing runs with -z (git C-quotes non-ASCII paths, which would silently fail the prefix match and drop a real change — a stale replay) and --no-renames (rename detection reports only the NEW path, so a project file renamed to a path outside the subtree would vanish from the listing; as delete+add both sides surface); - git show SHA:path (behavioural-change filtering, composer.lock drift summaries) resolves project-relative paths through the prefix. A new GitRepository helper locates the governing repository by walking ancestors, fixing three more root==project assumptions: Fingerprint's tracked-lockfile check, BaselineSync's GitHub-repo detection (baseline fetching silently never activated for subdirectory projects), and Storage's origin-based project key — which now also carries the subdirectory prefix, so `apps/api` and `services/api` in one repository never share a graph store. Root-level projects keep their exact existing behaviour: the prefix is empty and every translation is the identity. The TiaRequiresRepositoryRoot exception is removed along with the guard.
Resolves conflicts with the upstream Tia refactor: - Keep upstream's new branch-resolution flow (TiaRequiresCommit, TiaRequiresDefaultBranch, TiaRequiresRemote) while dropping the subdirectory panic and TiaRequiresRepositoryRoot, per this PR. - Rebuild ChangedFiles' repo-prefix detection on the new Pest\Support\Git class (subdirectoryPrefix()) instead of raw Symfony Process calls. - Keep the -z flag in diffSinceSha so non-ASCII filenames are not C-quoted, and translate diff output to project-relative paths. - Route composerLockDelta through ChangedFiles::contentAtSha so the baseline lookup is repo-prefix aware. - Rewrite the upstream feature test that expected nested projects to refuse to run: they now run from the subdirectory. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RioXB5bmhqgAd4rjH2spb4
# Conflicts: # tests/.snapshots/success.txt
|
Hey guys, this will be vey helpful! Also talked with several people waiting for this fix! Thanks for the great work🙏 |
Follow gitdir files and commondir pointers to locate the governing repository config. Cover GitHub and GitLab baseline detection with real worktrees and submodules, and refresh the suite output snapshots. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
|
thank you! closing in favor of #1914, which covers the same fix. |
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
Allow TIA to run when a Pest project lives inside a Git repository, such as
apps/apiin a monorepo. Translate repository paths into project paths so dependency selection, baseline detection, and graph storage use the correct project.ChangedFilesstrips the project prefix from Git output, adds it to paths passed to Git, and ignores sibling projects. Null-delimited output preserves non-ASCII filenames, and--no-renamespreserves deletions when files move outside the project.GitRepositoryfinds the nearest governing.gitentry. For worktrees and submodules, it follows thegitdirfile and resolves relative or absolute paths. Worktrees read the shared config throughcommondir; submodules read their own config. This fixes silent baseline detection failures for both GitHub and GitLab.Storagegives sibling projects separate graph stores, andFingerprintuses the governing repository for gitignore detection. Root-level projects retain their existing path translations and storage keys.Verified:
PEST_TIA=0 php bin/pest tests/Unit/Plugins/Tia/GitRepository.php tests/Unit/Plugins/Tia/Baselines.php --compactpasses all 28 cases, including real Git worktrees and submodules for both baseline providers..git/configand detectseinar-hansen/pestas its baseline repository.XDEBUG_MODE=off PEST_TIA=0 composer testpasses fore933e7f40704f72efcbc5b1b98d9fd93a15d2f56: lint, static analysis, 100% type coverage, unit tests, parallel tests, and integration tests (239 passed, 1 skipped). Local PHP 8.5.8 used Xdebug so fixtures could toggle coverage throughXDEBUG_MODE; PCOV was disabled for this run.composer test:profanitypasses. Output snapshots include the current suite totals.The GitHub baseline artifact name remains
pest-tia-baseline, so multiple baselined projects in one repository still share that artifact name.Related:
🤖 Generated with Claude Code