#!/usr/bin/env bash set -Eeuo pipefail REPO_ROOT="$(git rev-parse --show-toplevel)" cd "$REPO_ROOT" mapfile -d '' staged_files < <( git diff --cached --name-only --diff-filter=ACMRDTUXB -z ) if (( ${#staged_files[@]} == 0 )); then echo "No staged files; commit regression tests are not required." exit 0 fi staged_rust_sources=() for path in "${staged_files[@]}"; do printf ' staged input: %s\n' "$path" if [[ "$path" == *.rs && -f "$path" ]]; then staged_rust_sources+=("$path") fi done dirty_inputs=() while IFS= read -r -d '' path; do dirty_inputs+=("$path") done < <(git diff --name-only --diff-filter=ACMRDTUXB -z) while IFS= read -r -d '' path; do dirty_inputs+=("$path") done < <(git ls-files --others --exclude-standard -z) if (( ${#dirty_inputs[@]} > 0 )); then echo "Commit blocked: unstaged or untracked files would make staged test results ambiguous:" >&2 printf ' %s\n' "${dirty_inputs[@]}" >&2 echo "Stage or remove those files, then retry the commit." >&2 exit 1 fi command -v cargo >/dev/null 2>&1 || { echo "Commit blocked: cargo is unavailable." >&2 exit 1 } if (( ${#staged_rust_sources[@]} > 0 )); then echo "Checking staged Rust source formatting..." rustfmt --edition 2021 --check "${staged_rust_sources[@]}" fi echo "Running deterministic workspace tests..." cargo check --locked --workspace --exclude hcie-io --examples cargo test --locked --workspace --exclude hcie-io --lib --tests -- \ --skip benchmark_4k_stroke_on_multilayer_document echo "Mandatory Rust regression gate passed."