Skip to content

mgiovani/ai-arsenal / skills/git-commit

git-commit

Verified

Generate a conventional commit message (conventionalcommits.org) from the staged/unstaged diff and create the commit. Use when the user wants to commit, stage changes, or needs a commit message written. Not for release commits or changelogs (use git-release) or branch-finish workflows (use gitflow).

FileKindSize
SKILL.mdskill md3.3 KB
evals/evals.jsonconfig1.8 KB
evals/trigger-eval.jsonconfig1.6 KB
scripts/pre-commit-lint.shexecutablescript4.7 KB

scripts/pre-commit-lint.sh

View on GitHub
#!/usr/bin/env bash
# Hook: pre-commit-lint
# Purpose: Run linter before git commit to ensure code quality
# Event: PreToolUse (before "git commit" command)
#
# This hook:
# 1. Detects the project type (Node.js, Python, etc.)
# 2. Runs the appropriate linter if configured
# 3. Blocks commit if linting fails
# 4. Allows commit if linting passes or no linter is configured

set -euo pipefail

# JSON response helper functions
deny_commit() {
  local reason="$1"
  cat <<EOF
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "$reason"
  }
}
EOF
  exit 0
}

allow_commit() {
  # Implicit allow - no output needed
  exit 0
}

# Function to detect and run linter
run_linter() {
  local project_root
  project_root=$(git rev-parse --show-toplevel 2>/dev/null || pwd)

  cd "$project_root" || exit 1

  # Check for Makefile with lint target (highest priority)
  if [ -f "Makefile" ] && grep -q "^lint:" Makefile; then
    echo "πŸ” Running: make lint" >&2
    if ! make lint 2>&1; then
      deny_commit "Linting failed: make lint reported errors. Fix lint errors before committing."
    fi
    allow_commit
  fi

  # Check for package.json (Node.js project)
  if [ -f "package.json" ]; then
    # Check if lint script exists
    if command -v jq >/dev/null 2>&1 && jq -e '.scripts.lint' package.json >/dev/null 2>&1; then
      echo "πŸ” Running: npm run lint" >&2

      # Detect package manager
      if [ -f "bun.lockb" ] && command -v bun >/dev/null 2>&1; then
        if ! bun run lint 2>&1; then
          deny_commit "Linting failed: bun run lint reported errors. Fix lint errors before committing."
        fi
      elif [ -f "pnpm-lock.yaml" ] && command -v pnpm >/dev/null 2>&1; then
        if ! pnpm run lint 2>&1; then
          deny_commit "Linting failed: pnpm run lint reported errors. Fix lint errors before committing."
        fi
      elif [ -f "yarn.lock" ] && command -v yarn >/dev/null 2>&1; then
        if ! yarn run lint 2>&1; then
          deny_commit "Linting failed: yarn run lint reported errors. Fix lint errors before committing."
        fi
      elif command -v npm >/dev/null 2>&1; then
        if ! npm run lint 2>&1; then
          deny_commit "Linting failed: npm run lint reported errors. Fix lint errors before committing."
        fi
      fi
      allow_commit
    fi

    # Fallback: Try running eslint directly
    if command -v eslint >/dev/null 2>&1; then
      echo "πŸ” Running: eslint ." >&2
      if ! eslint . 2>&1; then
        deny_commit "Linting failed: eslint reported errors. Fix lint errors before committing."
      fi
      allow_commit
    fi

    # If bun is available, try bunx eslint
    if [ -f "bun.lockb" ] && command -v bunx >/dev/null 2>&1; then
      echo "πŸ” Running: bunx eslint ." >&2
      if ! bunx eslint . 2>&1; then
        deny_commit "Linting failed: bunx eslint reported errors. Fix lint errors before committing."
      fi
      allow_commit
    fi
  fi

  # Check for pyproject.toml (Python project)
  if [ -f "pyproject.toml" ]; then
    # Check for ruff (modern, fast linter)
    if command -v ruff >/dev/null 2>&1; then
      echo "πŸ” Running: ruff check ." >&2
      if ! ruff check . 2>&1; then
        deny_commit "Linting failed: ruff check reported errors. Fix lint errors before committing."
      fi
      allow_commit
    fi

    # Fallback to uv run ruff
    if command -v uv >/dev/null 2>&1; then
      echo "πŸ” Running: uv run ruff check ." >&2
      if ! uv run ruff check . 2>&1; then
        deny_commit "Linting failed: uv run ruff check reported errors. Fix lint errors before committing."
      fi
      allow_commit
    fi

    # Fallback to flake8
    if command -v flake8 >/dev/null 2>&1; then
      echo "πŸ” Running: flake8 ." >&2
      if ! flake8 . 2>&1; then
        deny_commit "Linting failed: flake8 reported errors. Fix lint errors before committing."
      fi
      allow_commit
    fi
  fi

  # Check for .rubocop.yml (Ruby project)
  if [ -f ".rubocop.yml" ] && command -v rubocop >/dev/null 2>&1; then
    echo "πŸ” Running: rubocop" >&2
    if ! rubocop 2>&1; then
      deny_commit "Linting failed: rubocop reported errors. Fix lint errors before committing."
    fi
    allow_commit
  fi

  # Check for .golangci.yml (Go project)
  if [ -f ".golangci.yml" ] && command -v golangci-lint >/dev/null 2>&1; then
    echo "πŸ” Running: golangci-lint run" >&2
    if ! golangci-lint run 2>&1; then
      deny_commit "Linting failed: golangci-lint reported errors. Fix lint errors before committing."
    fi
    allow_commit
  fi

  # No linter configuration found - allow commit
  echo "ℹ️  No linter configuration found. Allowing commit without linting." >&2
  allow_commit
}

# Main execution
run_linter
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 321kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 321kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 321kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 321kUpdated Claude CodeCodexVerifiedInstall