Commit 62b23b3
committed
Make git work in the dev container when opened from a worktree
When the dev container is opened from a git worktree, the worktree's
.git is a file whose `gitdir:` line points at a host path under the
main repo's .git/worktrees/<branch>. That host path is not visible
inside the container by default, so git inside the container fails
with "fatal: not a git repository: (null)" -- VS Code's safe.directory
probe, credential.helper setup, and any developer git command all hit
this.
Resolve the common git dir on the host in initializeCommand.sh via
`git rev-parse --git-common-dir`, write the absolute path into
.devcontainer/.env, and have docker-compose.yml bind-mount it at the
same path inside the container. The worktree's `.git` file's gitdir
reference then resolves cleanly. For a main checkout this is a
no-op-shaped redundant mount of <repo>/.git at the same host path
inside the container; nothing breaks.
.devcontainer/.env is generated per-launch and is gitignored.1 parent 0e2d13b commit 62b23b3
3 files changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
0 commit comments