Skip to content

Support launching the devcontainer from a git worktree#8950

Open
alliepiper wants to merge 2 commits into
NVIDIA:mainfrom
alliepiper:devcontainer-worktree-fix
Open

Support launching the devcontainer from a git worktree#8950
alliepiper wants to merge 2 commits into
NVIDIA:mainfrom
alliepiper:devcontainer-worktree-fix

Conversation

@alliepiper
Copy link
Copy Markdown
Contributor

Summary

Make .devcontainer/launch.sh work when invoked from a linked git worktree.

Two reasons it currently breaks:

  1. .git is unreachable inside the container. In a worktree, .git is
    a file containing gitdir: <main-repo>/.git/worktrees/<name> — an
    absolute host path. The container only mounts the worktree at
    /home/coder/cccl, so the gitdir pointer (and the main .git it
    references via commondir) is unreachable. Every git operation in
    the container fails.

  2. gh auth state is missing. The devcontainer bind-mounts
    ${localWorkspaceFolder}/.config → /home/coder/.config. In a fresh
    worktree, .config/gh/ doesn't exist, so
    devcontainer-utils-init-git falls through to an interactive
    gh auth login device flow on every startup.

Changes

.devcontainer/launch.sh launch_docker() now detects the worktree
case ([[ -f .git ]]) and:

  • Bind-mounts the main repo's .git directory at its absolute host path
    inside the container, so both the absolute gitdir: pointer and the
    relative commondir resolve.
  • Bind-mounts the main checkout's .config/gh (when present) into
    /home/coder/.config/gh, so gh auth status passes and
    devcontainer-utils-init-git skips the device flow.
  • Prints a warning that the global cccl-build and cccl-wheelhouse
    docker volumes are shared across all worktrees and the main
    checkout (preexisting issue, but worth surfacing).
  • If the main checkout has no .config/gh/ to share, additionally
    warns that init-git will block on gh auth login and recommends
    launching the main checkout's devcontainer first to populate auth
    state.

No-op when .git is a directory (regular checkout).

Test plan

  • Pre-commit (shellcheck, codespell, etc.) passes on .devcontainer/launch.sh.
  • End-to-end: .devcontainer/launch.sh -d -- bash -c '<git probes>'
    from the worktree completes without hanging on gh auth login.
    Inside the container:
    - gh auth status → ✓ Logged in as alliepiper
    - git statusOn branch devcontainer-worktree-fix (no
    "dubious ownership" error)
    - git rev-parse --git-dir
    /home/allie/code/src/cccl/.git/worktrees/devcontainer-worktree-fix
    - git rev-parse --git-common-dir/home/allie/code/src/cccl/.git
    - git log resolves commits correctly.

In a linked git worktree, `.git` is a file pointing to
<main-repo>/.git/worktrees/<name> via an absolute host path. The
container only mounts the worktree at /home/coder/cccl, so the gitdir
pointer (and the main .git it links back to via commondir) is
unreachable, and every git operation in the container fails. Bind-mount
the main repo's .git directory at its absolute host path inside the
container so both the absolute gitdir pointer and the relative commondir
resolve.

The devcontainer also bind-mounts ${localWorkspaceFolder}/.config to
/home/coder/.config, which in a fresh worktree has no gh/ subdir, so
devcontainer-utils-init-git triggers an interactive `gh auth login`
device flow on startup. When the main checkout has a populated
.config/gh, share it into the worktree container so init-git skips the
device flow. Otherwise warn that the user must launch the main
checkout's devcontainer first to populate auth state.

Also warn that `cccl-build` and `cccl-wheelhouse` docker volumes are
shared across all worktrees and the main checkout — preexisting issue,
but worth surfacing when the worktree case lights up.
@alliepiper alliepiper requested a review from a team as a code owner May 12, 2026 22:13
@alliepiper alliepiper requested a review from jrhemstad May 12, 2026 22:13
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 12, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 12, 2026
@alliepiper
Copy link
Copy Markdown
Contributor Author

"the devcontainer"

I'm a human I swear.

@github-actions

This comment has been minimized.

@alliepiper alliepiper enabled auto-merge (squash) May 13, 2026 17:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Enhanced dev container launch script to support Git worktree configurations, enabling improved Git operations within containers
    • Added automatic detection and mounting of shared Git configuration for worktree setups
    • Improved authentication handling to prevent unnecessary interactive login flows
    • Added warnings for potential artifact conflicts when running concurrent dev containers from linked worktrees

Walkthrough

The devcontainer launch script now detects when running from a Git worktree, computes the shared Git directory, and bind-mounts it into the container. It also conditionally mounts shared auth config and emits warnings about shared Docker volumes.

Changes

Devcontainer Git Worktree Integration

Layer / File(s) Summary
Git worktree detection and Docker mount configuration
.devcontainer/launch.sh
Worktree detection checks if .git is a file, computes the shared Git common directory, and bind-mounts it. Optional .config/gh auth config is also mounted. Multi-line warnings inform users about shared Docker volumes and potential artifact collisions between concurrent worktree containers.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 418c5a4d-63cc-455e-9cb4-76401d30f28e

📥 Commits

Reviewing files that changed from the base of the PR and between e49bdfa and 78a9efa.

📒 Files selected for processing (1)
  • .devcontainer/launch.sh

Comment thread .devcontainer/launch.sh
@github-actions
Copy link
Copy Markdown
Contributor

😬 CI Workflow Results

🟥 Finished in 2h 49m: Pass: 99%/500 | Total: 18d 17h | Max: 2h 48m | Hits: 23%/2836811

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants