Skip to content

Commit c905f16

Browse files
committed
chore: add pre-commit hooks (merge conflict check, web lint/tsc, shellcheck)
- Reject commits with merge conflict markers in staged files - When web/ is staged: run npm run lint and tsc -b in web/ - When scripts/ or .githooks/ change: run shellcheck if available Made-with: Cursor
1 parent adad365 commit c905f16

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

.githooks/pre-commit

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ set -euo pipefail
44
repo_root="$(git rev-parse --show-toplevel)"
55
cd "$repo_root"
66

7+
staged="$(git diff --cached --name-only)"
8+
9+
# Reject merge conflict markers in staged files
10+
conflicts_file=""
11+
if [ -n "$staged" ]; then
12+
conflicts_file="$(mktemp)"
13+
echo "$staged" | while IFS= read -r f; do
14+
[ -f "$f" ] && grep -q -E '^<<<<<<< |^=======$|^>>>>>>> ' "$f" 2>/dev/null && echo "$f" >> "$conflicts_file" || true
15+
done
16+
if [ -s "$conflicts_file" ]; then
17+
echo "ERROR: Staged files contain merge conflict markers (<<<<<<<, =======, >>>>>>>):"
18+
cat "$conflicts_file"
19+
rm -f "$conflicts_file"
20+
exit 1
21+
fi
22+
rm -f "$conflicts_file"
23+
fi
24+
725
echo "==> Validating GitHub workflows..."
826
bash "./scripts/check-workflows.sh"
927

@@ -13,6 +31,21 @@ cargo fmt --check
1331
echo "==> Running cargo clippy --all-targets..."
1432
cargo clippy --all-targets -- -D warnings
1533

34+
if echo "$staged" | grep -q '^web/'; then
35+
echo "==> Web files changed: running npm lint and tsc in web/..."
36+
(cd web && npm run lint)
37+
(cd web && npx tsc -b --noEmit)
38+
fi
39+
40+
if command -v shellcheck >/dev/null 2>&1; then
41+
if echo "$staged" | grep -qE '^scripts/|^\.githooks/'; then
42+
echo "==> Shell scripts changed: running shellcheck..."
43+
echo "$staged" | while IFS= read -r f; do
44+
case "$f" in scripts/*.sh|.githooks/pre-commit|.githooks/pre-push) [ -f "$f" ] && shellcheck -s bash "$f" ;; esac
45+
done
46+
fi
47+
fi
48+
1649
if [ "${SKIP_TESTS:-0}" = "1" ]; then
1750
echo "==> Skipping cargo test (SKIP_TESTS=1). Pre-push still enforces the full Rust gate."
1851
else

0 commit comments

Comments
 (0)