fix(shell): discover devcontainer from any subdir of a worktree or repo#9
Open
rosstaco wants to merge 1 commit into
Open
fix(shell): discover devcontainer from any subdir of a worktree or repo#9rosstaco wants to merge 1 commit into
rosstaco wants to merge 1 commit into
Conversation
Previously `dcode shell` (and `dcode <path>`) only looked at the exact target directory for a `.git` pointer. Running from any subdir of a worktree (e.g. `~/repos/repo_a/.worktrees/branch_1/src`) fell through to "no devcontainer.json found" because resolve_worktree only succeeded when the target itself was the worktree root. The same blind spot silently affected plain repos: `dcode .` from a subdir would fall back to plain `code <subdir>` with no container. Add `_find_project_root` which walks ancestors looking for a `.git` (file or directory), and `resolve_target` which returns `(project_root, container_subdir)` — the host directory that owns the devcontainer plus the path relative to the devcontainer's `workspaceFolder` that the user actually wants opened. For worktrees, project_root stays the main repo so all worktrees keep sharing one container, and container_subdir stacks the worktree-relative path and the user's subdir. `run_shell`, `run_dcode`, `check_devcontainer`, `check_devcontainer_parses` and the doctor plan summary all switch to `resolve_target` so they behave consistently from any depth. Tests: `TestFindProjectRoot`, `TestResolveTarget`, `TestRunDcodeSubdir` in test_core.py; `test_worktree_subdir_uses_main_repo_and_deeper_workdir` + `test_plain_repo_subdir_resolves_devcontainer_at_repo_root` in test_shell.py. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Problem
dcode shell(anddcode <path>) only looked at the exact targetdirectory for a
.gitpointer. Running from any subdir of a worktreefell through to "no devcontainer.json found":
The same blind spot silently affected plain repos:
dcode .from asubdir would fall back to plain
code <subdir>with no container.Fix
Two new helpers in
core.py:_find_project_root(target)— walks ancestors looking for a.git(file or directory). Returns the directory containing it.
resolve_target(target) -> (project_root, container_subdir)— thehost directory that owns the devcontainer plus the path relative to
the devcontainer's
workspaceFolderthat the user actually wantsopened. For worktrees, project_root stays the main repo (all worktrees
keep sharing one container) and container_subdir stacks the
worktree-relative path and the user's subdir. For plain repos it's
just the repo root + subdir. For non-repo targets it returns
(target, Path('.'))so the existing "no devcontainer" fallback isunchanged.
run_shell,run_dcode,check_devcontainer,check_devcontainer_parsesand the doctor plan summary all switch to
resolve_targetso theybehave consistently from any depth, including
dcode doctorwhich nowpredicts what
dcode .will actually do.After
Tests
333 passing, lint clean.
tests/test_core.py:TestFindProjectRoot(5 cases),TestResolveTarget(5 cases including non-repo fallback),TestRunDcodeSubdir(3 end-to-end: plain subdir, worktree subdir,non-repo fallback).
tests/test_shell.py:test_worktree_subdir_uses_main_repo_and_deeper_workdir(regressiontest for the reported bug, asserts
find_containerkeys off the mainrepo and
probe_workdirpoints at the deeper folder), plustest_plain_repo_subdir_resolves_devcontainer_at_repo_root.test_worktree_uses_main_repo_for_lookupstill passesunchanged (worktree-root behaviour is preserved).
repo" lowercase, and the external-worktree case which now reverts to
the clean "no devcontainer" plan instead of an alarming "cannot be
resolved" warning).
Out of scope
path-resolution fix.
check_worktreeis unchanged; it's specifically a per-target sanitycheck (is THIS folder a worktree pointer file?) so widening it to
walk-up would change its semantic.