Skip to content

devcontainer: add optional worktrees mount#3541

Merged
ben-dz merged 1 commit intomainfrom
bdz/devcontainer-worktrees-mount
Apr 17, 2026
Merged

devcontainer: add optional worktrees mount#3541
ben-dz merged 1 commit intomainfrom
bdz/devcontainer-worktrees-mount

Conversation

@ben-dz
Copy link
Copy Markdown
Contributor

@ben-dz ben-dz commented Apr 16, 2026

Summary

  • Adds an optional DZ_WORKTREES_DIR host env var that mounts a worktrees directory at /workspaces/worktrees inside the dev container, so docker exec workflows can reach git worktrees stored outside the main repo checkout
  • Defaults to /tmp/worktrees (created by initializeCommand) when the env var is unset — harmless empty mount for devs who don't opt in
  • Works with VS Code launched from Dock/Spotlight; VS Code's resolveShellEnv picks up the env var from shell rc

Motivation

The persistent dev container (dz-dev-workspace-vsc) is used via docker exec for Linux builds. Worktrees kept in a global location (e.g. ~/projects/worktrees/) are not visible inside the container without a mount, so switching between worktrees required constant rebuilds or host-side tooling.

Opt-in

Add one line to your shell rc:

export DZ_WORKTREES_DIR="$HOME/projects/worktrees"  # or wherever you keep worktrees

Then rebuild the dev container. Your worktrees appear at /workspaces/worktrees/ inside the container, mirroring the host layout.

Testing Verification

  • Rebuilt the dev container with DZ_WORKTREES_DIR set; confirmed mount source resolves to $HOME/projects/worktrees via docker inspect
  • Verified inside the container that /workspaces/worktrees/ shows host worktrees content
  • Verified the unset path: without the env var, mount source resolves to /tmp/worktrees, created by initializeCommand
  • Confirmed VS Code launched from Dock/Spotlight inherits the env var via resolveShellEnv

Add an optional `DZ_WORKTREES_DIR` mount that exposes a host worktrees
directory at /workspaces/worktrees inside the container. Useful when
using `docker exec` to run builds in the persistent dev container while
working on git worktrees outside the repo checkout.

Defaults to /tmp/worktrees (created by initializeCommand) when the env
var is unset, so the mount is a harmless no-op for devs who don't use
it.
@ben-dz ben-dz marked this pull request as ready for review April 17, 2026 16:54
@ben-dz ben-dz merged commit 952d0a7 into main Apr 17, 2026
33 checks passed
@ben-dz ben-dz deleted the bdz/devcontainer-worktrees-mount branch April 17, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants