From d948cdb63e53ab8789ea15e95defc2e522152683 Mon Sep 17 00:00:00 2001 From: leetcrypt Date: Sat, 6 Jun 2026 21:40:41 -0700 Subject: [PATCH] fix(scripts): host-house.sh builds from main by default Add a BRANCH guard (default: main) so launching the house never demos a stale checkout. ensure_branch() switches to $BRANCH before the cargo build, refuses when the tree is dirty (won't clobber uncommitted work), and no-ops when already on-branch or when BRANCH= is passed to keep the current checkout. Co-Authored-By: Claude Opus 4.6 --- hh/scripts/host-house.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/hh/scripts/host-house.sh b/hh/scripts/host-house.sh index 22a8c49..3302779 100755 --- a/hh/scripts/host-house.sh +++ b/hh/scripts/host-house.sh @@ -51,6 +51,7 @@ environment (override any default): PORT listen port (default: 4173) PW room password (default: random, openssl-generated) THEME theme name (church | neon | crypt) + BRANCH git branch to build (default: main; BRANCH= keeps current checkout) notes: - Two windows in one session: 'server' (host-room.sh — join banner + logs) and @@ -77,6 +78,7 @@ PORT="${PORT:-4173}" PW="${PW:-$(openssl rand -hex 12)}" THEMES_DIR="$HERE/themes" THEME="${THEME:-}" +BRANCH="${BRANCH-main}" # default: build from main; BRANCH= keeps current checkout USE_TLS=0; CERT=""; KEY="" DO_KILL=0 NAME="" @@ -106,6 +108,23 @@ while [[ $# -gt 0 ]]; do done NAME="${NAME:-${USER:-$(id -un)}}" +# Build from a known branch (default: main) so the house never demos a stale +# checkout. BRANCH= (empty) keeps whatever's checked out. Won't clobber dirty work. +ensure_branch() { + [[ -z "$BRANCH" ]] && return 0 + git -C "$ROOT" rev-parse --git-dir >/dev/null 2>&1 || return 0 + local cur + cur="$(git -C "$ROOT" symbolic-ref --short -q HEAD || echo DETACHED)" + [[ "$cur" == "$BRANCH" ]] && return 0 + if [[ -n "$(git -C "$ROOT" status --porcelain)" ]]; then + echo "✖ on '$cur' with uncommitted changes — can't switch to '$BRANCH'." >&2 + echo " commit/stash first, or run with BRANCH= to build '$cur' as-is." >&2 + exit 2 + fi + echo "⛧ switching $cur → $BRANCH before build" + git -C "$ROOT" switch "$BRANCH" || { echo "✖ couldn't switch to '$BRANCH'" >&2; exit 2; } +} + # Stop the server on $PORT (the one holding the port), used by --kill and before # we (re)launch so only the room we start answers on this port. stop_server() { @@ -160,8 +179,9 @@ fi is_up() { curl -s $CURLK --max-time 2 "$SCHEME://$CLIENT_HOST:$PORT/health" 2>/dev/null | grep -q '"status":"ok"'; } -# 1. build the client so the GUI pane has a binary to run. -echo "building client…" +# 1. build the client so the GUI pane has a binary to run — from $BRANCH (main). +ensure_branch +echo "building client… (branch: ${BRANCH:-current checkout})" ( cd "$HERE" && cargo build --quiet ) || { echo "✖ build failed"; exit 1; } # 2. clear the port so only the room we start answers on it.