Mount worktree common dir when a custom workspaceMount is set#1261
Mount worktree common dir when a custom workspaceMount is set#1261AvishayHirsh wants to merge 1 commit into
Conversation
The --mount-git-worktree-common-dir logic was nested inside the guard
that skips workspace mount computation when devcontainer.json sets both
workspaceFolder and workspaceMount. As a result the worktree common dir
was never mounted and git operations failed in the container
("fatal: not a git repository").
Decouple the additive common dir mount from that guard and resolve its
target relative to the custom (substituted) workspaceMount target so the
relative gitdir resolves correctly inside the container.
|
@microsoft-github-policy-service agree |
|
Thanks for the worktree common-dir feature in #1127! This is a small follow-up for #1243: the common-dir mount is skipped when The fix is gated behind the existing @Mathiyarasy @chrmarti would appreciate a workflow-run approval and a review whenever you have a moment — thanks! |
Fixes #1243
Problem
--mount-git-worktree-common-dir(added in #1127) is silently ignored when adevcontainer.jsonsets a customworkspaceMount. Git worktrees then break inside the container:This is common in monorepo setups where a custom
workspaceMount/workspaceFolderis used.Root cause
In
getWorkspaceConfiguration(src/spec-node/utils.ts), the worktree common-dir computation lives inside the guard that only auto-computesworkspaceMount/workspaceFolderwhen they aren't already set in the config:When the config sets both
workspaceFolderandworkspaceMount, the whole block is skipped, soadditionalMountString(the common-dir bind mount) is never built and the main repo's.gitis never mounted.Fix
The common-dir mount is an additive, separate mount — it can't conflict with a user-defined
workspaceMount, so it shouldn't be gated by the "don't overwrite user config" guard:--mount-git-worktree-common-dirdefaults tofalse, so default behavior is unchanged unless the flag is opted into.workspaceMounttarget. BecauseadditionalMountStringis not part of the later variable-substitution pass, the target is substituted here (handles the canonicaltarget=/workspaces/${localWorkspaceFolderBasename}). Without a custom mount, the previously computed target is used, so existing behavior is unchanged.Tests
Added unit tests in
src/test/workspaceConfiguration.test.ts(across linux/darwin/win32) covering: the reported scenario,${localWorkspaceFolderBasename}substitution in the target, feature-off no-op, non-worktree no-op, and a worktree nested inside the main repo.yarn lint,yarn type-check, and the test suite all pass locally.Known limitations (pre-existing, unchanged by this PR)
gitdiris handled (worktrees created withgit worktree add --relative-paths); absolute gitdirs were already unsupported.sourceis the worktree root (the directory holding the.gitfile).