Files
RedBear-OS/local/scripts/commit-msg
T
vasilito 87f3f908bf phase 9.1-9.2: add commit-msg hook + consolidate tool docs
Adds the commit-msg hook promised in HOOKS.md since Round 5.
The hook auto-prepends the current Red Bear development phase
(e.g. 'phase 8.4:') to commit messages. The phase is detected
from the most recent 'phase X.Y:' commit in the git log.

Hook behavior:
  - Normal commit    → prepended: 'phase 8.4: my message'
  - Already has prefix → skipped
  - Revert message   → skipped
  - Empty/comment    → skipped

Install: cp local/scripts/commit-msg .git/hooks/commit-msg && chmod +x

Updates HOOKS.md with:
  - commit-msg hook documentation (install, behavior)
  - Full tool inventory table (10 tools across 9+ rounds)
    listing each tool's type, purpose, and modes/flags
2026-07-12 12:20:29 +03:00

34 lines
961 B
Bash
Executable File

#!/usr/bin/env bash
# commit-msg — Optional commit-msg hook for Red Bear OS.
# Auto-prepends the current development phase to commit messages.
# Usage:
# cp local/scripts/commit-msg .git/hooks/commit-msg
# chmod +x .git/hooks/commit-msg
# The hook is OPT-IN. See local/docs/HOOKS.md.
set -euo pipefail
COMMIT_MSG_FILE="$1"
PHASE=""
# Detect current phase from the most recent "phase X.Y:" commit in log
detect_phase() {
PHASE=$(git log --oneline -50 2>/dev/null | grep -oP 'phase \d+\.\d+' | head -1)
[ -n "$PHASE" ] || PHASE="phase"
}
detect_phase
FIRST_LINE=$(head -1 "$COMMIT_MSG_FILE" 2>/dev/null)
# Already has phase prefix or is Revert — skip
echo "$FIRST_LINE" | grep -qE '^(phase [0-9]+\.[0-9]+):' && exit 0
echo "$FIRST_LINE" | grep -qE '^Revert ' && exit 0
# Empty or comment — skip
[ -z "$FIRST_LINE" ] && exit 0
echo "$FIRST_LINE" | grep -q '^#' && exit 0
# Prepend phase
sed -i "1s/^/${PHASE}: /" "$COMMIT_MSG_FILE"
exit 0