Skip to content

fix(build): make .version writes resilient to missing git HEAD#1207

Open
topitopongsala wants to merge 1 commit intogarrytan:mainfrom
topitopongsala:fix-build-script-git-rev-parse-resilience
Open

fix(build): make .version writes resilient to missing git HEAD#1207
topitopongsala wants to merge 1 commit intogarrytan:mainfrom
topitopongsala:fix-build-script-git-rev-parse-resilience

Conversation

@topitopongsala
Copy link
Copy Markdown

What

Wrap each git rev-parse HEAD > <dir>/dist/.version call in the build script with a subshell + fallback:

- && git rev-parse HEAD > browse/dist/.version
+ && (git rev-parse HEAD 2>/dev/null || echo unknown) > browse/dist/.version

(applied identically for design/dist/.version and make-pdf/dist/.version).

Why

When gstack is built outside its own git checkout — most notably Conductor's "Quick start → gstack template" flow, which clones gstack into a brand-new repo's .claude/skills/gstack/ (no .git of its own; parent repo has no commits, so HEAD is unborn) — git rev-parse HEAD exits 128 with:

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

The && chain then kills the entire build:

error: script "build" exited with code 128

…which surfaces in Conductor as Failed to create repo: error: script "build" exited with code 128 and the gstack template wipes the workspace before the user can inspect anything.

The .version files are pure metadata — they shouldn't be load-bearing on the build's success.

After this fix

  • Normal checkout (your dev machine): still writes the real commit SHA. ✅
  • Tarball / .git-less install / unborn parent HEAD: writes unknown and the build proceeds. ✅
  • Conductor "Quick start → gstack template": completes successfully. ✅

Verification

# Normal case
cd /tmp && git clone https://github.com/garrytan/gstack && cd gstack
git checkout fix-build-script-git-rev-parse-resilience
bun install && bun run build
cat browse/dist/.version  # → real SHA, exit 0

# Conductor-template case (no .git)
tmp=$(mktemp -d) && cp -R . "$tmp"/ && rm -rf "$tmp/.git" "$tmp/node_modules"
cd "$tmp" && bun install && bun run build
cat browse/dist/.version  # → "unknown", exit 0 (previously: exit 128)

Out of scope

This PR doesn't touch the broader question of whether the install flow should hand gstack a real .git or copy .version files in some other way — it's the smallest possible patch to stop killing the build. Happy to follow up if maintainers prefer a different approach.

The build script ends with three `git rev-parse HEAD > <dir>/dist/.version`
calls. When gstack is built outside its own git checkout (e.g. installed
into a fresh repo whose parent has no commits — Conductor's gstack template
flow), git walks up the tree, finds an unborn HEAD, and aborts with code
128. The `&&`-chain then kills the whole build:

    error: script "build" exited with code 128
    fatal: ambiguous argument 'HEAD': unknown revision or path not in
    the working tree.

Wrap each call in a subshell with a fallback so the build always succeeds:

    (git rev-parse HEAD 2>/dev/null || echo unknown) > <dir>/dist/.version

Behavior unchanged for normal checkouts — still writes the real SHA.
Failure mode now writes 'unknown' instead of aborting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant