|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +auto_update="${AUTO_UPDATE:-false}" |
| 6 | + |
| 7 | +prompts_path="" |
| 8 | +if [[ -d "${repo_root}/prompts/.git" || -f "${repo_root}/prompts/.git" ]]; then |
| 9 | + prompts_path="prompts" |
| 10 | +elif [[ -d "${repo_root}/third_party/prompts/.git" || -f "${repo_root}/third_party/prompts/.git" ]]; then |
| 11 | + prompts_path="third_party/prompts" |
| 12 | +fi |
| 13 | + |
| 14 | +if [[ -z "${prompts_path}" ]]; then |
| 15 | + echo "FAIL: prompts submodule not found at prompts/ or third_party/prompts/" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +local_sha="$(git -C "${repo_root}/${prompts_path}" rev-parse HEAD)" |
| 20 | +if ! git -C "${repo_root}/${prompts_path}" fetch origin main --quiet; then |
| 21 | + echo "FAIL: unable to fetch ${prompts_path} origin/main" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | +remote_sha="$(git -C "${repo_root}/${prompts_path}" rev-parse origin/main)" |
| 25 | + |
| 26 | +echo "prompts_path=${prompts_path}" |
| 27 | +echo "local_sha=${local_sha}" |
| 28 | +echo "remote_sha=${remote_sha}" |
| 29 | + |
| 30 | +if [[ "${local_sha}" == "${remote_sha}" ]]; then |
| 31 | + echo "PASS: prompts submodule is up to date" |
| 32 | + exit 0 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "WARN: prompts submodule is stale" |
| 36 | +if [[ "${auto_update}" == "true" ]]; then |
| 37 | + if git -C "${repo_root}" submodule status -- "${prompts_path}" >/dev/null 2>&1; then |
| 38 | + git -C "${repo_root}" submodule update --remote -- "${prompts_path}" |
| 39 | + updated_sha="$(git -C "${repo_root}/${prompts_path}" rev-parse HEAD)" |
| 40 | + echo "UPDATED_SUBMODULE: ${local_sha:0:7} -> ${updated_sha:0:7}" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + |
| 44 | + git -C "${repo_root}/${prompts_path}" checkout --detach "${remote_sha}" >/dev/null 2>&1 |
| 45 | + updated_sha="$(git -C "${repo_root}/${prompts_path}" rev-parse HEAD)" |
| 46 | + echo "UPDATED_WORKTREE_ONLY: ${local_sha:0:7} -> ${updated_sha:0:7}" |
| 47 | + exit 0 |
| 48 | +fi |
| 49 | + |
| 50 | +echo "Run: git submodule update --remote -- ${prompts_path}" |
| 51 | +exit 1 |
0 commit comments