rskv 0.1.0

High-performance KV store inspired by Microsoft FASTER
Documentation
# Pre-commit hook script for rskv project (PowerShell version)
# This script runs before each commit to ensure code quality

param(
    [switch]$SkipTests = $false
)

# Colors for output
$Red = "Red"
$Green = "Green"
$Yellow = "Yellow"
$Blue = "Blue"

function Write-ColorOutput {
    param(
        [string]$Message,
        [string]$Color = "White"
    )
    Write-Host $Message -ForegroundColor $Color
}

Write-ColorOutput "๐Ÿ” Running pre-commit checks..." $Blue

# Check if we're in a git repository
try {
    $null = git rev-parse --git-dir 2>$null
} catch {
    Write-ColorOutput "โŒ Not in a git repository" $Red
    exit 1
}

# Get staged files
$StagedFiles = git diff --cached --name-only --diff-filter=ACM | Where-Object { $_ -match '\.rs$' }

if (-not $StagedFiles) {
    Write-ColorOutput "โš ๏ธ  No Rust files staged for commit" $Yellow
    exit 0
}

Write-ColorOutput "๐Ÿ“ Staged Rust files:" $Blue
$StagedFiles | ForEach-Object { Write-Host "  $_" }

# Function to check if a command exists
function Test-Command {
    param([string]$Command)
    try {
        Get-Command $Command -ErrorAction Stop | Out-Null
        return $true
    } catch {
        return $false
    }
}

# Check code formatting
Write-ColorOutput "๐Ÿ”ง Checking code formatting..." $Yellow
try {
    cargo fmt --all -- --check
    if ($LASTEXITCODE -ne 0) {
        Write-ColorOutput "โŒ Code formatting check failed" $Red
        Write-ColorOutput "๐Ÿ’ก Run 'cargo fmt --all' to fix formatting issues" $Yellow
        exit 1
    }
    Write-ColorOutput "โœ… Code formatting check passed" $Green
} catch {
    Write-ColorOutput "โŒ Code formatting check failed" $Red
    exit 1
}

# Check clippy
Write-ColorOutput "๐Ÿ” Running clippy..." $Yellow
try {
    cargo clippy --all-features --workspace -- -D warnings
    if ($LASTEXITCODE -ne 0) {
        Write-ColorOutput "โŒ Clippy check failed" $Red
        exit 1
    }
    Write-ColorOutput "โœ… Clippy check passed" $Green
} catch {
    Write-ColorOutput "โŒ Clippy check failed" $Red
    exit 1
}

# Check compilation
Write-ColorOutput "๐Ÿ”จ Checking compilation..." $Yellow
try {
    cargo check --all-features --workspace
    if ($LASTEXITCODE -ne 0) {
        Write-ColorOutput "โŒ Compilation check failed" $Red
        exit 1
    }
    Write-ColorOutput "โœ… Compilation check passed" $Green
} catch {
    Write-ColorOutput "โŒ Compilation check failed" $Red
    exit 1
}

# Run tests (unless skipped)
if (-not $SkipTests) {
    Write-ColorOutput "๐Ÿงช Running tests..." $Yellow
    try {
        cargo test --all-features --workspace
        if ($LASTEXITCODE -ne 0) {
            Write-ColorOutput "โŒ Tests failed" $Red
            exit 1
        }
        Write-ColorOutput "โœ… Tests passed" $Green
    } catch {
        Write-ColorOutput "โŒ Tests failed" $Red
        exit 1
    }
} else {
    Write-ColorOutput "โš ๏ธ  Skipping tests (--SkipTests flag used)" $Yellow
}

# Security audit (if cargo-audit is available)
if (Test-Command "cargo-audit") {
    Write-ColorOutput "๐Ÿ”’ Running security audit..." $Yellow
    try {
        cargo audit
        if ($LASTEXITCODE -ne 0) {
            Write-ColorOutput "โŒ Security audit failed" $Red
            exit 1
        }
        Write-ColorOutput "โœ… Security audit passed" $Green
    } catch {
        Write-ColorOutput "โŒ Security audit failed" $Red
        exit 1
    }
} else {
    Write-ColorOutput "โš ๏ธ  cargo-audit not found, skipping security audit" $Yellow
}

# Cargo-deny check (if available)
if (Test-Command "cargo-deny") {
    Write-ColorOutput "๐Ÿ“‹ Running cargo-deny..." $Yellow
    try {
        cargo deny check
        if ($LASTEXITCODE -ne 0) {
            Write-ColorOutput "โŒ Cargo-deny check failed" $Red
            exit 1
        }
        Write-ColorOutput "โœ… Cargo-deny check passed" $Green
    } catch {
        Write-ColorOutput "โŒ Cargo-deny check failed" $Red
        exit 1
    }
} else {
    Write-ColorOutput "โš ๏ธ  cargo-deny not found, skipping dependency check" $Yellow
}

Write-ColorOutput "๐ŸŽ‰ All pre-commit checks passed!" $Green
Write-ColorOutput "๐Ÿ“ Ready to commit" $Blue