fix(legacy): do not create .git when writing the exclude file outside a repository - #187
Merged
Merged
Conversation
… a repository writeGitExclude() fell back to "$dir/.git/info/exclude" when "git rev-parse --git-path" failed, so running it in a directory that is not a Git repository created a bogus .git directory. That directory then made the CLI treat the parent as a project root, e.g. a stray /tmp/.git broke WelcomeCommandTest and GitServiceTest. Skip writing the exclude file when the directory is not in a repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests run commands in sys_get_temp_dir(), and the CLI searches parent directories for a Git repository, so a stray .git there leaks into tests with confusing failures. Fail early with a clear message instead, as the Go integration tests do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Warning
Changes suggested — 🟡 1 warning
🔍 Full review · 3 files reviewed
Verification
- When
writeGitExcludegets a null path, it returns before anydumpFile, so no.git/infodirectory is created outside a repository. - In the bootstrap loop,
dirname($dir) === $dirends the walk at the filesystem root, for both/and Windows drive roots, so the loop cannot run forever. - The new test's expected string 'Automatically added by the Mock CLI' matches
application.name: 'Mock CLI'in tests/data/mock-cli-config.yaml.
The PR adds LocalProjectTest, with two tests: one writes the exclude file in a fresh git init repo, and one checks that no .git is created outside a repository. It also adds a bootstrap guard that stops PHPUnit if a .git exists in or above the temp directory. No test covers a real repository where the git rev-parse call fails.
Review details
- Commit: 70a6716
- Model: claude-opus-5-5
Review 1 of 10 for this pull request · View the full run
…repository If `git rev-parse` fails in a real repository (e.g. Git is not on PATH, or safe.directory rejects it), still write to "$dir/.git/info/exclude" when "$dir/.git" is a directory, so the web root stays excluded. Only skip writing when there is no .git directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
LocalProject::writeGitExclude()fell back to$dir/.git/info/excludewhengit rev-parse --git-pathfailed. So in a directory that isn't a Git repository, it created a.gitdirectory. The CLI then treated that directory as a project root.A stray
/tmp/.gitcreated this way made PHPUnit'sWelcomeCommandTest(Configuration not defined: detection.git_remote_name) andGitServiceTest::testGetRootfail, becauseMockAppruns commands insys_get_temp_dir()..gitexists in or above the temp directory. The Go integration tests already guard against this (test(integration): isolate each test's working and home directories #166).🤖 Generated with Claude Code