First full working version.
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to install git hooks
|
||||
|
||||
HOOK_DIR="$(git rev-parse --git-dir)/hooks"
|
||||
SCRIPT_DIR="$(dirname "$0")"
|
||||
|
||||
echo "Installing git hooks..."
|
||||
|
||||
# Copy pre-commit hook
|
||||
if [ -f "$SCRIPT_DIR/pre-commit" ]; then
|
||||
cp "$SCRIPT_DIR/pre-commit" "$HOOK_DIR/pre-commit"
|
||||
chmod +x "$HOOK_DIR/pre-commit"
|
||||
echo "✓ Installed pre-commit hook"
|
||||
else
|
||||
echo "✗ pre-commit hook not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Git hooks installed successfully!"
|
||||
echo
|
||||
echo "To bypass hooks for a commit, use: git commit --no-verify"
|
||||
echo "To uninstall hooks, delete files in: $HOOK_DIR"
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Running pre-commit checks..."
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}✓${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}✗${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠${NC} $1"
|
||||
}
|
||||
|
||||
# Check if cargo is available
|
||||
if ! command -v cargo &> /dev/null; then
|
||||
print_error "Cargo is not installed or not in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for staged Rust files
|
||||
staged_rust_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(rs)$' || true)
|
||||
|
||||
if [ -z "$staged_rust_files" ]; then
|
||||
print_warning "No Rust files staged for commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Staged Rust files:"
|
||||
echo "$staged_rust_files"
|
||||
echo
|
||||
|
||||
# 1. Check formatting
|
||||
echo "📝 Checking code formatting..."
|
||||
if ! cargo fmt -- --check; then
|
||||
print_error "Code formatting check failed!"
|
||||
echo "Run 'cargo fmt' to fix formatting issues"
|
||||
exit 1
|
||||
fi
|
||||
print_status "Code formatting is correct"
|
||||
|
||||
# 2. Run Clippy
|
||||
echo "📎 Running Clippy linter..."
|
||||
if ! cargo clippy --all-features --all-targets -- -D warnings; then
|
||||
print_error "Clippy found issues!"
|
||||
echo "Fix the issues above or run 'cargo clippy --fix' for automatic fixes"
|
||||
exit 1
|
||||
fi
|
||||
print_status "Clippy checks passed"
|
||||
|
||||
# 3. Run tests
|
||||
echo "🧪 Running tests..."
|
||||
if ! cargo test --all-features; then
|
||||
print_error "Tests failed!"
|
||||
echo "Fix failing tests before committing"
|
||||
exit 1
|
||||
fi
|
||||
print_status "All tests passed"
|
||||
|
||||
# 4. Check for security vulnerabilities (optional - only if cargo-audit is installed)
|
||||
if command -v cargo-audit &> /dev/null; then
|
||||
echo "🔒 Running security audit..."
|
||||
if ! cargo audit; then
|
||||
print_error "Security vulnerabilities found!"
|
||||
echo "Review and fix security issues before committing"
|
||||
exit 1
|
||||
fi
|
||||
print_status "Security audit passed"
|
||||
else
|
||||
print_warning "cargo-audit not installed. Run 'cargo install cargo-audit' to enable security checks"
|
||||
fi
|
||||
|
||||
# 5. Check that the project builds
|
||||
echo "🔨 Building project..."
|
||||
if ! cargo build --all-features; then
|
||||
print_error "Build failed!"
|
||||
exit 1
|
||||
fi
|
||||
print_status "Build successful"
|
||||
|
||||
echo
|
||||
echo -e "${GREEN}🎉 All pre-commit checks passed!${NC}"
|
||||
echo "Proceeding with commit..."
|
||||
Reference in New Issue
Block a user