Skip to content

Commit aed82f9

Browse files
gilesknapclaude
andcommitted
fix(devcontainer): only init missing submodules on container start
git submodule update --init runs on every postCreate, which on container rebuild moves any submodule whose HEAD differs from the parent's pinned SHA into detached HEAD — silently yanking in-progress branch work in initialized submodules. The data isn't lost (reachable via reflog and existing branches) but recovery requires submodule literacy that not every user has. Filter to only the uninitialized submodules using git submodule status output (leading '-'), preserving the first-clone build protection without touching already-checked-out submodules. Applies to all generated projects, not just the Claude-sandbox case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 19099d9 commit aed82f9

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

.devcontainer/postCreate.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ uv venv --clear
66
uv sync
77
pre-commit install --install-hooks
88

9-
# Initialise git submodules if any are declared
10-
[ -f .gitmodules ] && git submodule update --init || true
9+
# Init only submodules that aren't checked out yet — first-clone
10+
# protection without touching already-initialized submodules (which
11+
# would yank in-progress branch work to detached HEAD on rebuild).
12+
if [ -f .gitmodules ]; then
13+
missing=$(git submodule status | awk '/^-/ {print $2}')
14+
[ -n "$missing" ] && git submodule update --init $missing
15+
fi

template/.devcontainer/postCreate.sh.jinja

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ uv venv --clear
99
uv sync
1010
pre-commit install --install-hooks
1111

12-
# Initialise git submodules if any are declared
13-
[ -f .gitmodules ] && git submodule update --init || true
12+
# Init only submodules that aren't checked out yet — first-clone
13+
# protection without touching already-initialized submodules (which
14+
# would yank in-progress branch work to detached HEAD on rebuild).
15+
if [ -f .gitmodules ]; then
16+
missing=$(git submodule status | awk '/^-/ {print $2}')
17+
[ -n "$missing" ] && git submodule update --init $missing
18+
fi

0 commit comments

Comments
 (0)