Skip to content

Commit 2a62ea2

Browse files
flyingrobotsclaude
andcommitted
feat(dev): add cross-platform git hooks and fix line ending config
- Add git hooks as managed artifacts in scripts/git-hooks/ - pre-commit: extreme quality enforcement with formatting, linting, tests - pre-push: comprehensive validation before sharing code - commit-msg: conventional commit format enforcement - Update setup-dev-env.sh for cross-platform git hook installation - Prefer symlinks for automatic updates - Fall back to copying on Windows without symlink support - Provide clear guidance for enabling Windows symlinks - Fix git line ending configuration for cross-platform compatibility - Windows: core.autocrlf=true (convert LF↔CRLF) - Linux/macOS: core.autocrlf=input (preserve LF, warn about CRLF) - Repository stores LF line endings consistently 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 069b13a commit 2a62ea2

4 files changed

Lines changed: 309 additions & 119 deletions

File tree

scripts/git-hooks/commit-msg

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
# HyperDAG commit-msg hook - Enforce conventional commit format
3+
# This hook validates commit messages for consistency and clarity
4+
5+
set -eu
6+
7+
commit_file="$1"
8+
commit_msg=$(cat "$commit_file")
9+
10+
# Check for conventional commit format
11+
# Pattern: type(optional scope): description
12+
# Examples: feat(core): add hypergraph structure, fix(memory): resolve leak in pool allocator
13+
14+
if ! echo "$commit_msg" | grep -qE '^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\(.+\))?: .{1,50}'; then
15+
cat << EOF
16+
❌ Invalid commit message format!
17+
18+
Commit messages must follow conventional commit format:
19+
<type>[optional scope]: <description>
20+
21+
Valid types:
22+
feat: A new feature
23+
fix: A bug fix
24+
docs: Documentation only changes
25+
style: Changes that do not affect the meaning of the code
26+
refactor: A code change that neither fixes a bug nor adds a feature
27+
perf: A code change that improves performance
28+
test: Adding missing tests or correcting existing tests
29+
chore: Changes to the build process or auxiliary tools
30+
ci: Changes to CI configuration files and scripts
31+
build: Changes that affect the build system or external dependencies
32+
33+
Examples:
34+
✓ feat(core): add hypergraph node insertion
35+
✓ fix(memory): resolve pool allocator leak
36+
✓ docs: update API documentation
37+
✓ perf(traversal): optimize DFS algorithm
38+
39+
Your commit message:
40+
$commit_msg
41+
42+
EOF
43+
exit 1
44+
fi
45+
46+
# Check commit message length
47+
first_line=$(echo "$commit_msg" | head -n1)
48+
if [ ${#first_line} -gt 72 ]; then
49+
cat << EOF
50+
❌ Commit message first line too long (${#first_line} chars)!
51+
52+
First line should be 72 characters or less.
53+
Current: $first_line
54+
55+
EOF
56+
exit 1
57+
fi
58+
59+
# Check for imperative mood in description
60+
description=$(echo "$first_line" | sed -E 's/^[^:]+: //')
61+
if echo "$description" | grep -qE '^(added|fixed|updated|changed|removed)'; then
62+
cat << EOF
63+
⚠️ Consider using imperative mood in commit description.
64+
65+
Instead of: "added feature" → use: "add feature"
66+
Instead of: "fixed bug" → use: "fix bug"
67+
68+
Current: $description
69+
70+
EOF
71+
# Non-blocking warning
72+
fi
73+
74+
echo "✅ Commit message format is valid"

scripts/git-hooks/pre-commit

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
# HyperDAG pre-commit hook - Extreme quality enforcement
3+
# This hook runs before every commit to ensure code quality standards
4+
5+
set -eu
6+
7+
# Import shared utilities
8+
. "$(git rev-parse --show-toplevel)/scripts/shlib.sh"
9+
10+
echo "🔧 Running pre-commit quality checks..."
11+
12+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
13+
pushd "$PROJECT_ROOT" >/dev/null
14+
15+
# Format all staged C/C++ files
16+
echo "📝 Formatting staged files..."
17+
git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|h|cpp|hpp)$' | while read -r file; do
18+
if [ -f "$file" ]; then
19+
clang-format -i "$file"
20+
git add "$file"
21+
echo " ✓ Formatted: $file"
22+
fi
23+
done
24+
25+
# Run quick static analysis on staged files
26+
echo "🔍 Running clang-tidy on staged files..."
27+
git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp)$' | while read -r file; do
28+
if [ -f "$file" ]; then
29+
if ! clang-tidy "$file" --quiet; then
30+
echo "❌ clang-tidy failed for: $file"
31+
popd >/dev/null
32+
exit 1
33+
fi
34+
echo " ✓ Clean: $file"
35+
fi
36+
done
37+
38+
# Check include guards
39+
echo "🛡️ Checking include guards..."
40+
if ! ./scripts/check-include-guards.sh; then
41+
echo "❌ Include guard check failed"
42+
popd >/dev/null
43+
exit 1
44+
fi
45+
46+
# Check version consistency
47+
echo "📋 Checking version consistency..."
48+
if ! ./scripts/check-version-consistency.sh; then
49+
echo "❌ Version consistency check failed"
50+
popd >/dev/null
51+
exit 1
52+
fi
53+
54+
# Run quick tests if available
55+
if [ -d "build" ] && [ -f "build/Makefile" ]; then
56+
echo "🧪 Running quick tests..."
57+
if ! ./scripts/run-quick-tests.sh; then
58+
echo "❌ Quick tests failed"
59+
popd >/dev/null
60+
exit 1
61+
fi
62+
fi
63+
64+
popd >/dev/null
65+
echo "✅ All pre-commit checks passed!"
66+
echo "💡 Tip: Run 'make all' to ensure full build compatibility"

scripts/git-hooks/pre-push

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
# HyperDAG pre-push hook - Comprehensive validation before sharing
3+
# This hook runs before pushing to ensure shared code meets extreme quality standards
4+
5+
set -eu
6+
7+
# Import shared utilities
8+
. "$(git rev-parse --show-toplevel)/scripts/shlib.sh"
9+
10+
echo "🚀 Running pre-push validation..."
11+
12+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
13+
pushd "$PROJECT_ROOT" >/dev/null
14+
15+
# Full static analysis
16+
echo "🔍 Running comprehensive static analysis..."
17+
if ! ./scripts/run-clang-tidy.sh; then
18+
echo "❌ Static analysis failed"
19+
popd >/dev/null
20+
exit 1
21+
fi
22+
23+
# Security scan
24+
echo "🛡️ Running security audit..."
25+
if ! ./scripts/security-audit.sh; then
26+
echo "❌ Security audit failed"
27+
popd >/dev/null
28+
exit 1
29+
fi
30+
31+
# Full test suite
32+
if [ -d "build" ]; then
33+
echo "🧪 Running full test suite..."
34+
if ! make -C build test; then
35+
echo "❌ Test suite failed"
36+
popd >/dev/null
37+
exit 1
38+
fi
39+
40+
# Memory leak detection if ASan is available
41+
echo "🧪 Checking for memory leaks..."
42+
if [ -f "build/bin/hyperdag_tests" ]; then
43+
if ! ASAN_OPTIONS="abort_on_error=1:detect_leaks=1" build/bin/hyperdag_tests; then
44+
echo "❌ Memory leak detected"
45+
popd >/dev/null
46+
exit 1
47+
fi
48+
fi
49+
fi
50+
51+
# Performance regression check
52+
if [ -d "benchmarks" ]; then
53+
echo "📊 Running performance regression check..."
54+
if ! ./scripts/profile.sh --check-regression; then
55+
echo "⚠️ Performance regression detected (non-blocking)"
56+
fi
57+
fi
58+
59+
popd >/dev/null
60+
echo "✅ All pre-push checks passed!"
61+
echo "🎉 Code is ready for sharing - maintaining extreme quality standards!"

0 commit comments

Comments
 (0)