#!/usr/bin/env bash # Clone the revisions pinned in sources.env, or move an existing checkout onto # them. Refuses to touch a directory whose origin is not the pinned repo. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" # shellcheck source=sources.env source ./sources.env clone_pinned() { local dir="$1" repo="$2" sha="$3" if [ -d "$dir" ]; then if ! git -C "$dir" rev-parse --git-dir >/dev/null 2>&1; then echo "$dir exists but is not a Git checkout; move it aside before continuing." >&2 exit 1 fi local actual_remote actual_remote="$(git -C "$dir" remote get-url origin 2>/dev/null || true)" if [ "$actual_remote" != "$repo" ]; then echo "$dir has origin $actual_remote, expected $repo; use a separate clone or fix origin deliberately." >&2 exit 1 fi else git clone --quiet "$repo" "$dir" fi git -C "$dir" fetch --quiet origin "$sha" 2>/dev/null || git -C "$dir" fetch --quiet origin git -C "$dir" -c advice.detachedHead=false checkout --quiet "$sha" } clone_pinned ./jetstream "$JETSTREAM_REPO" "$JETSTREAM_SHA" clone_pinned ./microcosm-rs "$MICROCOSM_REPO" "$MICROCOSM_SHA"