rs-stats 2.0.3

Statistics library in rust
Documentation
#!/bin/sh
# Pre-commit hook to enforce workflow rules
#
# This hook:
# - Prevents commits to main/master branch
# - Validates workflow sequence (issue moves committed before work files)
# - Warns about catch-all git add commands
#
# Installation:
#   cp scripts/pre-commit-hook .git/hooks/pre-commit
#   chmod +x .git/hooks/pre-commit
#
# Bypass (emergency only):
#   git commit --no-verify

# Get current branch
CURRENT_BRANCH=$(git branch --show-current)

# Check if committing to main or master
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
    echo "❌ WORKFLOW VIOLATION: Cannot commit directly to main."
    echo ""
    echo "Required: Create a feature branch first"
    echo "Remediation:"
    echo "  1. Create branch: git checkout -b feat/your-feature"
    echo "  2. Commit on feature branch"
    echo "  3. Create PR when ready"
    echo ""
    echo "If this is an emergency, use: git commit --no-verify"
    echo "(But this should be extremely rare)"
    exit 1
fi

# Get staged files
STAGED_FILES=$(git diff --cached --name-only)

# Check for workflow sequence violations
ISSUE_FILES=$(echo "$STAGED_FILES" | grep -E '^issues/[^/]+/(todo|in_progress|done)/.*\.md$' || true)
WORK_FILES=$(echo "$STAGED_FILES" | grep -vE '^issues/' || true)

# If committing work files, check if issue move to in_progress/ was committed first
if [ -n "$WORK_FILES" ] && [ -n "$ISSUE_FILES" ]; then
    # Check if any issue file is being moved to in_progress/
    MOVING_TO_IN_PROGRESS=$(echo "$ISSUE_FILES" | grep '/in_progress/' || true)
    
    if [ -z "$MOVING_TO_IN_PROGRESS" ]; then
        # Work files and issue files staged together, but issue not moving to in_progress/
        # This might be OK if issue is already in in_progress/, but warn
        echo "⚠️  WARNING: Staging work files together with issue files"
        echo "   Ensure issue move to in_progress/ was committed before work files"
        echo ""
    fi
fi

# Check if committing work files but issue still in todo/
if [ -n "$WORK_FILES" ]; then
    # Check if there are any issues in todo/ directory
    for issue_dir in issues/*/todo/; do
        if [ -d "$issue_dir" ]; then
            TODO_ISSUES=$(find "$issue_dir" -name "*.md" -type f 2>/dev/null | head -1)
            if [ -n "$TODO_ISSUES" ]; then
                # Check if we're also staging an issue move
                STAGED_ISSUE_MOVE=$(echo "$ISSUE_FILES" | grep '/in_progress/' || true)
                if [ -z "$STAGED_ISSUE_MOVE" ]; then
                    echo "⚠️  WARNING: Committing work files but issue may still be in todo/"
                    echo "   Ensure issue was moved to in_progress/ and committed first"
                    echo "   Issue files found in: $issue_dir"
                    echo ""
                fi
            fi
        fi
    done
fi

# Optional: Check staged files count (warn about catch-all)
STAGED_COUNT=$(echo "$STAGED_FILES" | wc -l | tr -d ' ')
if [ "$STAGED_COUNT" -gt 20 ]; then
    echo "⚠️  WARNING: Many files staged ($STAGED_COUNT files)"
    echo "   This might indicate use of 'git add -A' or 'git add .'"
    echo "   Consider using explicit file paths: git add <specific-file>"
    echo ""
fi

# All checks passed
exit 0