#!/usr/bin/env bash # verify-clean-clone.sh -- run the suite from a FRESH CLONE, never the working copy. # # BLOCKER 1 EXISTED BECAUSE EVERY RUN HAPPENED WHERE THE EXEC BIT WAS ALREADY SET. # Two people ran 32/32 on files whose local mode had been set by hand at creation # time; the COMMITTED mode was 100644, so the delivered artifact returned 126 # Permission denied and aborted before printing a summary. The artifact had never # run for anyone. # # "Run it somewhere real" was not enough. The missing word is CLEAN: run it from a # checkout that carries only what the repository actually stores. Local state you # did not commit is invisible to you precisely because it is yours. # # This script commits the artifacts into a scratch repo, clones that repo, and # runs the suite from the clone -- so the only modes in play are the ones git # recorded. It also asserts the mode positively, so a future commit that drops the # bit fails here instead of at the next reviewer. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT ARTIFACTS=(push-guard.sh test-push-guard.sh) printf '=== packaging from %s ===\n' "$HERE" mkdir -p "$WORK/src" for f in "${ARTIFACTS[@]}"; do cp "$HERE/$f" "$WORK/src/$f" done [[ -f "$HERE/README.md" ]] && cp "$HERE/README.md" "$WORK/src/README.md" cd "$WORK/src" git init -q . git config user.email "clean@example.invalid" git config user.name "Clean Clone" git add -A # THE ASSERTION THAT WOULD HAVE CAUGHT BLOCKER 1. # Check the mode in the INDEX -- what git will actually store -- not the mode on # disk, which is what misled us. These differ exactly when it matters. rc=0 for f in "${ARTIFACTS[@]}"; do mode="$(git ls-files -s -- "$f" | awk '{print $1}')" if [[ "$mode" != "100755" ]]; then printf ' FAIL %s is mode %s in the index (needs 100755)\n' "$f" "$mode" printf ' fix with: git update-index --chmod=+x %s\n' "$f" rc=1 else printf ' ok %s is mode %s in the index\n' "$f" "$mode" fi done (( rc == 0 )) || { printf '\nREFUSING TO CONTINUE: the committed modes are wrong.\n'; exit 1; } git commit -q -m "artifacts under test" printf '\n=== cloning (no local mode bits survive this) ===\n' cd "$WORK" git clone -q src clone cd clone for f in "${ARTIFACTS[@]}"; do printf ' clone mode: %s %s\n' "$(stat -c '%a' "$f")" "$f" done printf '\n=== executing DIRECTLY (./script), not via `bash script` ===\n' # Running `bash script` masks a missing exec bit completely -- it is how the # original 32/32 was obtained. Direct execution is the thing under test. if ! ./test-push-guard.sh; then printf '\nCLEAN-CLONE RUN FAILED.\n' exit 1 fi printf '\n=== CLEAN CLONE: suite ran and passed from a fresh checkout ===\n'