Skip to content

Commit a50a36f

Browse files
authored
feat: add pre-commit hook for format and lint checks (#7)
Runs cargo ci-fmt and ci-lint before each commit to catch formatting and clippy issues before they reach CI. Tests are skipped by default (too slow) but can be enabled with REF_SOLVER_PRECOMMIT_TEST=1. Install with: cp scripts/hooks/pre-commit .git/hooks/pre-commit
1 parent e50f011 commit a50a36f

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

scripts/hooks/pre-commit

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
#
3+
# Pre-commit hook for ref-solver
4+
#
5+
# Runs cargo ci-fmt and ci-lint before each commit.
6+
# ci-test is skipped by default (too slow) but can be enabled with:
7+
# REF_SOLVER_PRECOMMIT_TEST=1 git commit
8+
#
9+
# To bypass the hook entirely (use sparingly):
10+
# git commit --no-verify
11+
12+
set -e
13+
14+
echo "Running pre-commit checks..."
15+
16+
# Check if we're in the right directory
17+
if [[ ! -f "Cargo.toml" ]]; then
18+
echo "Error: Not in ref-solver root directory"
19+
exit 1
20+
fi
21+
22+
# Run formatting check
23+
echo "==> cargo ci-fmt"
24+
if ! cargo ci-fmt; then
25+
echo ""
26+
echo "Formatting check failed!"
27+
echo "Run 'cargo fmt' to fix formatting issues."
28+
exit 1
29+
fi
30+
31+
# Run linting check
32+
echo "==> cargo ci-lint"
33+
if ! cargo ci-lint; then
34+
echo ""
35+
echo "Lint check failed!"
36+
echo "Fix the clippy warnings above before committing."
37+
exit 1
38+
fi
39+
40+
# Optionally run tests
41+
if [[ "${REF_SOLVER_PRECOMMIT_TEST:-0}" == "1" ]]; then
42+
echo "==> cargo ci-test"
43+
if ! cargo ci-test; then
44+
echo ""
45+
echo "Tests failed!"
46+
exit 1
47+
fi
48+
else
49+
echo "==> Skipping ci-test (set REF_SOLVER_PRECOMMIT_TEST=1 to enable)"
50+
fi
51+
52+
echo ""
53+
echo "Pre-commit checks passed!"

0 commit comments

Comments
 (0)