Skip to content

Commit 6c08e63

Browse files
gilesknapclaude
andcommitted
fix(postCreate): graceful handling 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. VS Code's wrapper hides the real stderr, leaving an exit-1 stack trace with no clue about the cause. postCreate.sh now detects a missing .git directory, prints a clear warning explaining what's happening, falls back to SETUPTOOLS_SCM_PRETEND_VERSION_FOR_<DIST>=0.0.0 so uv sync finishes, and skips pre-commit install (which needs .git/hooks). Once the user runs `git init && git add . && git commit`, re-running the script picks up the real version from git automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5cf9c82 commit 6c08e63

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

template/.devcontainer/postCreate.sh.jinja

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,44 @@ set -euo pipefail
44
# Install Claude Code CLI
55
curl -fsSL https://claude.ai/install.sh | bash
66
{% endif %}
7+
# setuptools-scm derives the package version from git tags, and
8+
# pre-commit installs its hooks into .git/hooks. If the project hasn't
9+
# been `git init`-ed yet, fall back to a pretend version so `uv sync`
10+
# can finish, skip the hook install, and tell the user how to switch
11+
# to a real setup. Subsequent `uv sync` runs (after `git init` and a
12+
# commit) will recompute the real version from git automatically.
13+
if [ ! -d .git ]; then
14+
cat <<'EOF'
15+
16+
================================================================
17+
WARNING: This directory is not a git repository.
18+
19+
- Using SETUPTOOLS_SCM_PRETEND_VERSION_FOR_{{ distribution_name | replace('-', '_') | replace('.', '_') | upper }}=0.0.0
20+
so `uv sync` can finish without setuptools-scm failing.
21+
- Skipping `pre-commit install` (it needs .git/hooks).
22+
23+
To get a real version and pre-commit hooks, run later:
24+
25+
git init && git add . && git commit -m 'Initial commit'
26+
.devcontainer/postCreate.sh
27+
28+
================================================================
29+
30+
EOF
31+
export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_{{ distribution_name | replace('-', '_') | replace('.', '_') | upper }}=0.0.0
32+
fi
33+
734
# Install Python dependencies and pre-commit hooks
835
uv venv --clear
936
uv sync
10-
pre-commit install --install-hooks
37+
if [ -d .git ]; then
38+
pre-commit install --install-hooks
39+
fi
1140

1241
# Init only submodules that aren't checked out yet — first-clone
1342
# protection without touching already-initialized submodules (which
1443
# would yank in-progress branch work to detached HEAD on rebuild).
15-
if [ -f .gitmodules ]; then
44+
if [ -d .git ] && [ -f .gitmodules ]; then
1645
missing=$(git submodule status | awk '/^-/ {print $2}')
1746
[ -n "$missing" ] && git submodule update --init $missing
1847
fi

0 commit comments

Comments
 (0)