Skip to content

Tia: support projects located in a git subdirectory - #2033

Open
k2-tek wants to merge 1 commit into
pestphp:5.xfrom
k2-tek:tia-git-subdirectory
Open

k2-tek wants to merge 1 commit into
pestphp:5.xfrom
k2-tek:tia-git-subdirectory

Conversation

@k2-tek

@k2-tek k2-tek commented Nov 15, 2026

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

Problem. When the project lives in a subdirectory of a larger git repository (for example app/backend), Tia compares paths that git reports relative to the repository root (git diff --name-only, git status --porcelain) against graph keys that are relative to the project. They never match, so changed files are not mapped to tests. In 4.7.x this was a silent false green (only arch tests selected); in 5.2+ Tia::handleParent() panics with TiaRequiresRepositoryRoot instead.

Reproduction.

git init && mkdir -p app/backend && cd app/backend
composer require pestphp/pest ... # project in app/backend, repo root is two levels up
vendor/bin/pest --tia   # TiaRequiresRepositoryRoot (5.2+), false green (4.7.x)

Change.

  • diffSinceSha: git diff --name-only --relative sha..HEAD. --relative yields project-relative paths and excludes files outside the subdirectory.
  • workingTreeChanges: keeps status --porcelain -z (always root-relative), strips the git rev-parse --show-prefix prefix and drops entries outside the subdirectory. For renames/copies each of the two paths is handled independently, so a rename out of the project still reports the old in-project path, and a rename into the project reports the new one.
  • Git::show: git show sha:./path, which git resolves against the working directory. This also covers the composer.lock baseline lookup.
  • check-ignore already receives project-relative paths and runs with the project as cwd, so it needed no change.
  • Removed the TiaRequiresRepositoryRoot guard and exception: nothing in the subdirectory case remains unhandled. When the project is the repository root the prefix is empty and behaviour is unchanged (./ is a no-op there).

Tests. tests/Unit/Plugins/Tia/ChangedFilesSubdirectory.php builds a temporary repo with the project in app/backend and a sibling directory, and covers: diff since a sha, modified/untracked status, renames into/out of/within the project, gitignored files, behaviourally unchanged files (uses show), Git::show, and the repository-root case. Without the source changes 6 of 7 fail. composer test:lint, test:type:check, test:type:coverage and test:unit pass locally.

Backward compatibility. Repository-root projects behave exactly as before. Projects in a subdirectory go from a hard error to working. TiaRequiresRepositoryRoot was @internal.

One thing for maintainers: Fingerprint::isTrackedByGit skips its git check-ignore when the project has no .git of its own, so in a subdirectory project lockfile/config files are treated as tracked even if ignored. This was already the case and is left untouched here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N4yeezMMbXx22bzRpWJbGo

Tia compared repository-root-relative paths returned by git against
project-relative graph keys, so a project in e.g. `app/backend` never
matched and Tia refused to run (TiaRequiresRepositoryRoot).

- diff: pass `--relative`, which also drops files outside the project
- status: strip the `--show-prefix` prefix and drop entries outside the
  project, handling both sides of renames and copies
- show: resolve `sha:./path` against the working directory
- remove the TiaRequiresRepositoryRoot guard, which is now handled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4yeezMMbXx22bzRpWJbGo
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.

1 participant