File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Local pre-commit guardrails for auths-dev/verify.
3+ #
4+ # Install once per clone:
5+ # git config core.hooksPath .githooks
6+ set -euo pipefail
7+
8+ fail=0
9+
10+ # 1. Block merge conflict markers and whitespace errors in staged changes.
11+ # `git diff --check` is purpose-built for this.
12+ if ! git diff --cached --check; then
13+ echo " "
14+ echo " ERROR: staged changes contain merge conflict markers or whitespace errors (see above)." >&2
15+ fail=1
16+ fi
17+
18+ # 2. Block src/ changes that forget to rebuild dist/.
19+ # If any src/**/*.ts is staged but nothing under dist/ is staged, CI will reject the commit
20+ # because `git diff --exit-code -- dist/` will fail. Catch it locally.
21+ staged=$( git diff --cached --name-only --diff-filter=ACMR)
22+ src_changed=$( printf ' %s\n' " $staged " | grep -E ' ^src/.*\.(ts|tsx)$' || true)
23+ dist_changed=$( printf ' %s\n' " $staged " | grep -E ' ^dist/' || true)
24+
25+ if [ -n " $src_changed " ] && [ -z " $dist_changed " ]; then
26+ echo " ERROR: src/ has staged changes but dist/ does not." >&2
27+ echo " Run 'npm run build' and stage dist/ before committing." >&2
28+ echo " (CI enforces this via .github/workflows/ci.yml -> 'Check dist is committed'.)" >&2
29+ fail=1
30+ fi
31+
32+ exit " $fail "
You can’t perform that action at this time.
0 commit comments