fix: warn when running inside a nested project, for #8321#8327
fix: warn when running inside a nested project, for #8321#8327stasadev wants to merge 2 commits into
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
tyler36
left a comment
There was a problem hiding this comment.
Works as intended.
I wonder if the warning would be better at the bottom of the table?
While testing in a VSCode terminal (a paneled terminal inside the main app), I had to scroll up to see the warning. Placing the warning last would make it more visible.
Tests
$ ddev -v
ddev version v1.25.1-80-g952d03d9bddev config --auto && ddev start
$ cd matomo && ddev describe
Nested project at "/home/user47/tmp/ddev-8327/matomo" overrides parent at "/home/user47/tmp/ddev-8327"
If this is not intended, run the command from the parent project root directory.
...
Good idea, but it depends on the command - for Maybe we should add global pre/post-run checks for this instead, since having projects inside projects is quite unusual. |
I like it. |
952d03d to
df3a207
Compare
|
The logic has been updated, see the changes in the first post. |
|
Confirming DDEV now prints warning after table.
|
## The Issue - Fixes ddev#8321 When a user runs `ddev` from inside a directory that has a parent project, the command silently used whichever project was found first walking up the tree, with no indication a nested project structure was detected. ## How This PR Solves The Issue `CheckForConf` now detects when a nested `.ddev/config.yaml` is found inside a directory that already belongs to a parent project. It emits a one-time warning naming both paths and returns the nested (inner) project. ## Manual Testing Instructions 1. `ddev config --auto && ddev start` 2. `git clone https://github.com/matomo-org/matomo` 3. `cd matomo && ddev describe` — a nested project warning should appear ## Automated Testing Overview `TestCheckForConf` in `pkg/ddevapp/utils_test.go` covers: - No config found: error returned - Config only in parent: parent path returned, no warning - Config in both parent and child: child path returned with warning ## Release/Deployment Notes Minor UX improvement, no breaking changes. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
## The Issue - Fixes ddev#8321 When a user runs `ddev` from inside a directory that has a parent project, the command silently used whichever project was found first walking up the tree, with no indication a nested project structure was detected. The most common symptom: a user has a custom command defined in the parent project, runs it from a subdirectory that is itself a DDEV project, and sees a cryptic "unknown command" error with no explanation. ## How This PR Solves The Issue A new `DetectNestedProject()` function in `pkg/ddevapp/utils.go` walks up from the current directory and returns the child and parent project roots when two `.ddev/config.yaml` files are found in an ancestor relationship. The warning is emitted in `Execute()` in `cmd/ddev/cmd/root.go` - after Cobra runs - so it fires for every invocation including unknown commands (Cobra skips all hooks for those, so placing it in `PersistentPreRun` would miss the most common case). The warning is suppressed for `--json-output` and shell-completion invocations. `ddev describe -j` gains a `parent_approot` field when run from a nested project. This is intended for IDE integrations such as [DDEV Integration](https://github.com/ddev/ddev-intellij-plugin) (JetBrains) and [DDEV Manager](https://github.com/ddev/vscode-ddev-manager) (VS Code): if `parent_approot` is present, the integration knows it is looking at a nested project and can act accordingly - for example, by not auto-starting project containers. ## Manual Testing Instructions 1. In a DDEV project directory, `ddev config --auto && ddev start` 2. `git clone https://github.com/matomo-org/matomo` 3. `cd matomo && ddev describe` - a nested project warning should appear after the output 4. `cd matomo && ddev some-custom-command-from-parent` - warning should appear alongside the "unknown command" error, explaining why the command is missing 5. `cd matomo && ddev describe -j | jq -r .raw.parent_approot` - should print the parent project root path 6. From the parent directory: `ddev describe -j | jq -r .raw.parent_approot` - should print `null` ## Automated Testing Overview New `TestDetectNestedProject` and `TestCheckForConf` in `pkg/ddevapp/utils_test.go` New `TestNestedProjectWarning` in `cmd/ddev/cmd/root_test.go` ## Release/Deployment Notes Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
df3a207 to
ac47039
Compare
|
Rebased just to get green build hopefully, now that wsl2 fix is green. Hopefully I can review tomorrow. |
|
This solves the unintended shell/custom command problem, but doesn't solve the |
rfay
left a comment
There was a problem hiding this comment.
Thanks for doing this, which solves a part of the problem, but I don't think it solves enough of it to go into v1.25.2 yet. We may want to think about expanding the scope a bit , either choosing to use the parent project, or providing some kind of config to sort this out. Or at least providing guidance to add-ons and others that try this kind of thing.
It's so ugly that ddev describe shows the nested project before showing the warning, and so ugly that ddev start tries to start the nested project. ddev snapshot tries to start and take a snapshot of the child.
The warning is easy to move and show before the command. |
The Issue
When a user runs
ddevfrom inside a directory that has a parent project, the command silently used whichever project was found first walking up the tree, with no indication a nested project structure was detected. The most common symptom: a user has a custom command defined in the parent project, runs it from a subdirectory that is itself a DDEV project, and sees a cryptic "unknown command" error with no explanation.How This PR Solves The Issue
A new
DetectNestedProject()function inpkg/ddevapp/utils.gowalks up from the current directory and returns the child and parent project roots when two.ddev/config.yamlfiles are found in an ancestor relationship.The warning is emitted in
Execute()incmd/ddev/cmd/root.go- after Cobra runs - so it fires for every invocation including unknown commands (Cobra skips all hooks for those, so placing it inPersistentPreRunwould miss the most common case). The warning is suppressed for--json-outputand shell-completion invocations.ddev describe -jgains a.raw.parent_approotfield when run from a nested project. This is intended for IDE integrations such as DDEV Integration (JetBrains) and DDEV Manager (VS Code): ifparent_approotis present, the integration knows it is looking at a nested project and can act accordingly - for example, by not auto-starting project containers.Manual Testing Instructions
ddev config --auto && ddev startgit clone https://github.com/matomo-org/matomocd matomo && ddev describe- a nested project warning should appear after the outputcd matomo && ddev some-custom-command-from-parent- warning should appear alongside the "unknown command" error, explaining why the command is missingcd matomo && ddev describe -j | jq -r .raw.parent_approot- should print the parent project root pathddev describe -j | jq -r .raw.parent_approot- should printnullAutomated Testing Overview
New
TestDetectNestedProjectandTestCheckForConfinpkg/ddevapp/utils_test.goNew
TestNestedProjectWarningincmd/ddev/cmd/root_test.goRelease/Deployment Notes
The warning fires on every command when a nested project is detected. This is intentional for now - we want to be noisy so users notice the situation, and we can gather feedback before deciding on a more permanent solution (e.g. a config option to suppress the warning).
Nested DDEV projects are unusual because they are confusing, but they do occur in real workflows - a notable example is Drupal core development, where contrib modules may each have their own
.ddev/config.yaml. This PR does not change how DDEV resolves which project to use in that situation; it only makes the ambiguity visible. Further changes will be driven by community feedback.