Skip to content

Commit c4f8b83

Browse files
committed
build: add githook
1 parent b736d76 commit c4f8b83

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.githooks/pre-commit

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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"

0 commit comments

Comments
 (0)