|
| 1 | +#!/usr/bin/env bash |
| 2 | +# test.sh — regression lock for the repo line-ending policy (#216) |
| 3 | +# |
| 4 | +# Locks the two load-bearing facts of .gitattributes: |
| 5 | +# 1. The deliberate CRLF fixture keeps its CRLF bytes (the -text exemption is |
| 6 | +# present AND effective). Without this lock, deleting the -text line would |
| 7 | +# silently degrade fixture 19-section-replace-crlf from a CRLF test into an |
| 8 | +# LF test with no failing test anywhere (#216 verify, devils-advocate finding). |
| 9 | +# 2. The global `* text=auto eol=lf` policy line exists, so newly added CRLF |
| 10 | +# text files normalize to LF in the index. |
| 11 | +# |
| 12 | +# Read-only: no index/working-tree mutation (safe to run with staged changes). |
| 13 | + |
| 14 | +set -u |
| 15 | + |
| 16 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../../.." && pwd)" |
| 17 | +FIXTURE="plugins/issue-driven-dev/scripts/tests/idd-edit/fixtures/19-section-replace-crlf/input.md" |
| 18 | +PASS=0 |
| 19 | +FAIL=0 |
| 20 | + |
| 21 | +check() { # <label> <cmd...> |
| 22 | + local label="$1"; shift |
| 23 | + if "$@" > /dev/null 2>&1; then |
| 24 | + echo " ✓ $label"; PASS=$((PASS + 1)) |
| 25 | + else |
| 26 | + echo " ✗ $label"; FAIL=$((FAIL + 1)) |
| 27 | + fi |
| 28 | +} |
| 29 | + |
| 30 | +cd "$REPO_ROOT" || { echo "✗ cannot cd to repo root"; exit 1; } |
| 31 | + |
| 32 | +# 1a. .gitattributes exists with the global LF policy line |
| 33 | +check "policy: .gitattributes has global '* text=auto eol=lf'" \ |
| 34 | + grep -qE '^\* text=auto eol=lf$' .gitattributes |
| 35 | + |
| 36 | +# 1b. the CRLF fixture has an explicit -text exemption line |
| 37 | +check "policy: fixture has -text exemption line" \ |
| 38 | + grep -qF "$FIXTURE -text" .gitattributes |
| 39 | + |
| 40 | +# 2. attribute resolution: text must be UNSET for the fixture (exemption effective) |
| 41 | +TEXT_ATTR="$(git check-attr text -- "$FIXTURE" | awk -F': ' '{print $NF}')" |
| 42 | +check "check-attr: fixture 'text' resolves to unset (got: $TEXT_ATTR)" \ |
| 43 | + test "$TEXT_ATTR" = "unset" |
| 44 | + |
| 45 | +# 3. index state: fixture is stored with CRLF (i/crlf) |
| 46 | +INDEX_EOL="$(git ls-files --eol -- "$FIXTURE" | awk '{print $1}')" |
| 47 | +check "index: fixture stored as i/crlf (got: $INDEX_EOL)" \ |
| 48 | + test "$INDEX_EOL" = "i/crlf" |
| 49 | + |
| 50 | +# 4. working copy bytes: fixture actually contains CRLF sequences |
| 51 | +check "worktree: fixture bytes contain CRLF" \ |
| 52 | + grep -q $'\r' "$FIXTURE" |
| 53 | + |
| 54 | +echo "================================" |
| 55 | +echo "Results: $PASS passed, $FAIL failed" |
| 56 | +[ "$FAIL" -eq 0 ] |
0 commit comments