Skip to content

Commit 19e9846

Browse files
gilesknapclaude
andcommitted
fix(postCreate): fail fast with a clear message when .git is missing
If the user opens the devcontainer before running `git init`, uv sync fails opaquely because setuptools-scm can't compute a version, and pre-commit can't install hooks into a non-existent .git/hooks. VS Code's wrapper then hides the real stderr behind a generic "postCreateCommand failed" exit-1. postCreate.sh now detects a missing .git directory up front, prints a clear explanation to stderr, and exits 1. The user is told exactly what to run on the host to recover. Failing fast beats silently bootstrapping a half-broken environment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5cf9c82 commit 19e9846

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

template/.devcontainer/postCreate.sh.jinja

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ set -euo pipefail
44
# Install Claude Code CLI
55
curl -fsSL https://claude.ai/install.sh | bash
66
{% endif %}
7+
# Refuse to continue without a git repo. setuptools-scm needs git
8+
# tags to compute the package version, and pre-commit installs its
9+
# hooks into .git/hooks — both fail with cryptic errors that VS Code
10+
# then hides behind a generic "postCreateCommand failed" message.
11+
# Better to stop here with a clear explanation.
12+
if [ ! -d .git ]; then
13+
cat >&2 <<'EOF'
14+
15+
================================================================
16+
ERROR: This directory is not a git repository.
17+
18+
setuptools-scm needs git history to compute the package version,
19+
and pre-commit installs its hooks into .git/hooks. Neither will
20+
work without a git repo.
21+
22+
To fix this, run on the host (outside the devcontainer):
23+
24+
git init -b main && git add . && git commit -m 'Initial commit'
25+
26+
then rebuild the devcontainer.
27+
28+
================================================================
29+
30+
EOF
31+
exit 1
32+
fi
33+
734
# Install Python dependencies and pre-commit hooks
835
uv venv --clear
936
uv sync

0 commit comments

Comments
 (0)