fix(config): resolve git branch under PHP-FPM by walking up to the repo root - #5
Merged
Merged
Conversation
…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>
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.
Summary
GitBranchResolver::fromGlobals()usedgetcwd()verbatim as the repository root. Under PHP-FPM the working directory is the front controller directory (typicallypublic/), one level below the repository root, so.git/HEADwas never found and the mini bar always showed "unknown".fromGlobals()now walks up fromgetcwd()to the first directory containing a.gitentry:.gitcannot pick up an unrelated repository further up (e.g. a versioned/var/www)..gitentry, including a.gitfile (worktree/submodule pointer):resolve()then yieldsnullinstead of climbing past it into an unrelated parent repository.file_get_contents()handling: anopen_basedirboundary crossed during the walk cannot break the page render when a consumer error handler converts warnings to exceptions.GIT_BRANCHoverride precedence is unchanged — the env override is checked inresolve()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
public/, multi-level walk-up, depth bound, stop at worktree.gitfile, fallback when nothing is found, start dir already containing.git.Fixes #4
🤖 Generated with Claude Code