OverviewFilesCommitsIssuesDocsReleasesPeers

pgh / scripts / install-version-guard.sh

45 lines · bash ref:
#!/bin/sh
# install-version-guard — install the pre-commit version-bump guard into the
# fleet's file: workspace packages (and pgh itself).
#
# Idempotent: re-running overwrites the hook with the current version. If a
# repo already has a different pre-commit hook, we chain to it.
#
# Usage:  sh scripts/install-version-guard.sh
#         FLEET_ROOT=/path sh scripts/install-version-guard.sh   (override base)

set -e

HERE=$(cd "$(dirname "$0")" && pwd)
HOOK_SRC="$HERE/hooks/pre-commit-version-guard.sh"
FLEET_ROOT="${FLEET_ROOT:-$(cd "$HERE/../.." && pwd)}"   # hyper-fleeky/

# file: workspace packages that get bundled by other apps + the tools.
REPOS="
hyper-overlay
hyper-deploy
hyper-svc
hyper-rooms
pgh-runtime
repos/hyperident
pgh
pgh-sidecar
"

installed=0
for rel in $REPOS; do
  repo="$FLEET_ROOT/$rel"
  git -C "$repo" rev-parse --git-dir >/dev/null 2>&1 || { echo "skip $rel (not a git repo)"; continue; }
  # Resolve the real hooks dir — works for plain repos, submodules (.git file),
  # and worktrees.
  hookdir=$(git -C "$repo" rev-parse --git-path hooks)
  case "$hookdir" in /*) ;; *) hookdir="$repo/$hookdir" ;; esac
  mkdir -p "$hookdir"
  cp "$HOOK_SRC" "$hookdir/pre-commit"
  chmod +x "$hookdir/pre-commit"
  echo "installed → $rel/.git/hooks/pre-commit"
  installed=$((installed + 1))
done

echo "version-bump guard installed in $installed repo(s)."