Skip to content

fix(config): resolve git branch under PHP-FPM by walking up to the repo root - #5

Merged
marcstraube merged 1 commit into
masterfrom
fix/fpm-repo-root-discovery
Jul 27, 2026
Merged

fix(config): resolve git branch under PHP-FPM by walking up to the repo root#5
marcstraube merged 1 commit into
masterfrom
fix/fpm-repo-root-discovery

Conversation

@marcstraube

Copy link
Copy Markdown
Owner

Summary

GitBranchResolver::fromGlobals() used getcwd() verbatim as the repository root. Under PHP-FPM the working directory is the front controller directory (typically public/), one level below the repository root, so .git/HEAD was never found and the mini bar always showed "unknown".

fromGlobals() now walks up from getcwd() to the first directory containing a .git entry:

  • Bounded depth (3 parent levels): a deployment without .git cannot pick up an unrelated repository further up (e.g. a versioned /var/www).
  • Stops at any .git entry, including a .git file (worktree/submodule pointer): resolve() then yields null instead of climbing past it into an unrelated parent repository.
  • Warning-safe existence checks, matching the existing file_get_contents() handling: an open_basedir boundary crossed during the walk cannot break the page render when a consumer error handler converts warnings to exceptions.
  • GIT_BRANCH override precedence is unchanged — the env override is checked in resolve() before any file access.

The walk lives in discoverRepoRoot(), marked @internal (public only so tests can drive it with a temp directory); the constructor contract is untouched.

Testing

  • 6 new test cases: walk-up from public/, multi-level walk-up, depth bound, stop at worktree .git file, fallback when nothing is found, start dir already containing .git.
  • Full suite: 413 tests, 1068 assertions, green. PHPStan, Psalm, PHPMD, Rector, Deptrac and php-cs-fixer all pass.

Fixes #4

🤖 Generated with Claude Code

…po root

GitBranchResolver::fromGlobals() used getcwd() verbatim as the repository
root. Under PHP-FPM the working directory is the front controller
directory (typically public/), one level below the repository root, so
.git/HEAD was never found and the mini bar always showed "unknown".

fromGlobals() now walks up from getcwd() to the first directory
containing a .git entry (bounded at 3 parent levels so a deployment
without .git cannot pick up an unrelated repository further up). The
walk stops at any .git entry including a .git file (worktree/submodule
pointer): resolve() then yields null instead of climbing past it into an
unrelated parent repository. Existence checks during the walk are
warning-safe, matching the existing file_get_contents() handling, so an
open_basedir boundary cannot break the page render. The GIT_BRANCH
override precedence is unchanged.

Fixes #4

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@marcstraube
marcstraube merged commit c1b9948 into master Jul 27, 2026
8 checks passed
@marcstraube
marcstraube deleted the fix/fpm-repo-root-discovery branch July 27, 2026 02:43
@marcstraube marcstraube added the bug Something isn't working label Jul 27, 2026
@marcstraube marcstraube self-assigned this Jul 27, 2026
@marcstraube marcstraube added the effort:m Medium (30 min - 2h) label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort:m Medium (30 min - 2h)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitBranchResolver returns null under PHP-FPM (getcwd() is the front controller directory)

1 participant