Silence git dubious ownership error in the wp-env test environment - #2652
Merged
Conversation
Docker Desktop on macOS presents the bind-mount point for
wp-content/plugins/performance as owned by 0:0, while everything beneath
it correctly carries the host user's UID. Git checks the ownership of the
repository directory itself, so it sees a mismatch and refuses to operate:
fatal: detected dubious ownership in repository at
'/var/www/html/wp-content/plugins/performance'
Composer shells out to git to determine the root package version, so every
`composer` invocation in the test container prints that error along with
"Composer could not detect the root package (wordpress/performance)
version, defaulting to '1.0.0'". Nothing actually fails, but the noise
appears above the output of every `npm run test-php:*` command and reads
like a fatal error.
Add an `afterStart` lifecycle script that registers the mount path in the
container's global git config. `--replace-all` keeps the entry unique
across repeated starts. Linux bind mounts report real ownership and never
hit this, where the command is simply a harmless no-op.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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
No separate issue was filed for this.
Every
npm run test-php:*command currently prints a scary-looking block before the tests run:Nothing actually fails — PHPUnit runs fine immediately afterwards — but it says
fataland is easy to mistake for a broken environment.Relevant technical choices
The cause is specific to Docker Desktop on macOS. Inside the container, the bind-mount point itself reports as root-owned while its contents carry the host user's UID:
Git checks the ownership of the repository directory, sees
0:0against a process running as501, and refuses (thesafe.directoryprotection added in Git 2.35.2 for CVE-2022-24765). Composer shells out to git to determine the root package version —composer.jsonhas noversionkey — so the error surfaces on every Composer invocation in that container.This adds an
afterStartlifecycle script registering the mount path in the container's global git config:--replace-allrather than--add, so repeated starts do not append duplicate entries.--config=.wp-env.test.jsonflag is repeated because lifecycle scripts run on the host and inheritprocess.envbut not the CLI flags. Locally overridden settings are still honored: wp-env derives.wp-env.test.override.jsonfrom the custom config path and merges it last, so the nestedwp-env runtargets the same containers..wp-env.test.jsonneeds this..wp-env.jsonhas nomappingsentry for the repo root, so no git repository is mounted at a path where Composer runs in the development environment.Verified by removing the config from the container, confirming the error returned, then running
npm run wp-env-test -- startand confirming both that the entry was restored and that Composer no longer emits the warning at all — it now detects the version from git as intended.npm run lint-jsonconfirms the file still validates againsthttps://schemas.wp.org/trunk/wp-env.json.Use of AI Tools
This change was written by Claude Opus 5 via Claude Code, working from a real failure observed locally. The diagnosis was verified empirically inside the running container rather than assumed — including the ownership mismatch shown above, wp-env's use of
docker compose exec(which is why a--globalwrite persists), and the override-merge behavior — by reading the@wordpress/envsource. The change and its reasoning were reviewed before submitting.