#!/usr/bin/env bash # Require every crates/ or legacy src/ change to carry a changed binding page. # Read one changed path per line on stdin. With --index, inspect candidate wiki # pages from Git's staged snapshot rather than the possibly different worktree. set -euo pipefail cd "$(dirname "$0")/.." mode=worktree case "${1:-}" in "") ;; --worktree) ;; --index) mode=index ;; *) echo "usage: $0 [--worktree|--index] < changed-paths" >&2; exit 2 ;; esac changed=$(cat) [ -n "$changed" ] || { echo "No files changed" exit 0 } grep -qE '^(crates/|src/)' <<< "$changed" || { echo "No crates/ or src/ files changed" exit 0 } is_binding_page() { local path="$1" case "$path" in wiki/*.md) ;; *) return 1 ;; esac if [ "$mode" = index ]; then git cat-file -e ":$path" 2>/dev/null || return 1 git grep --cached -qE '^Type: (law|spec)$' -- "$path" else [ -f "$path" ] && grep -qE '^Type: (law|spec)$' "$path" fi } while IFS= read -r path; do [ -n "$path" ] || continue if is_binding_page "$path"; then echo "Design corpus check passed" exit 0 fi done <<< "$changed" echo "DESIGN CORPUS VIOLATION" echo " A crates/ (or src/) change must amend a changed Type: law or Type: spec" echo " page under wiki/. Root DESIGN.md does not count." exit 1