Skip to content

fix(legacy): do not create .git when writing the exclude file outside a repository - #187

Merged
pjcdawkins merged 3 commits into
mainfrom
claude/welcome-command-test-config-a12ba0
Sep 28, 2026
Merged

pjcdawkins merged 3 commits into
mainfrom
claude/welcome-command-test-config-a12ba0

Conversation

@pjcdawkins

Copy link
Copy Markdown
Contributor

LocalProject::writeGitExclude() fell back to $dir/.git/info/exclude when git rev-parse --git-path failed. So in a directory that isn't a Git repository, it created a .git directory. The CLI then treated that directory as a project root.

A stray /tmp/.git created this way made PHPUnit's WelcomeCommandTest (Configuration not defined: detection.git_remote_name) and GitServiceTest::testGetRoot fail, because MockApp runs commands in sys_get_temp_dir().

🤖 Generated with Claude Code

pjcdawkins and others added 2 commits September 27, 2026 23:47
… 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>

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Changes suggested — 🟡 1 warning

🔍 Full review · 3 files reviewed

Verification
  • When writeGitExclude gets a null path, it returns before any dumpFile, so no .git/info directory is created outside a repository.
  • In the bootstrap loop, dirname($dir) === $dir ends 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

Comment thread legacy/src/Local/LocalProject.php Outdated
…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>
@pjcdawkins
pjcdawkins merged commit 4886e11 into main Sep 28, 2026
6 checks passed
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