From 8eb8ad3a2cd51277dc3d763b64175357dad01398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Tr=C3=B6ger?= Date: Thu, 4 Jun 2026 08:30:32 +0200 Subject: [PATCH] feat: .commit-on-main Opt-out fuer Branch-Schutz Co-Authored-By: Claude Opus 4.6 --- .commit-on-main | 0 CLAUDE.md | 4 ++-- hooks/pre-bash-checks.sh | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .commit-on-main diff --git a/.commit-on-main b/.commit-on-main new file mode 100644 index 0000000..e69de29 diff --git a/CLAUDE.md b/CLAUDE.md index 1f76fff..d1b47c1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -117,7 +117,7 @@ Kurzbefehl für den gesamten Ablauf: `/story` | Event | Trigger | Skript | Aktion | |---|---|---|---| -| `PreToolUse` | Bash | `hooks/pre-bash-checks.sh` | Git-main-Schutz, Commit-Message-Validierung (Conventional Commits), apt -y Blockade | +| `PreToolUse` | Bash | `hooks/pre-bash-checks.sh` | Git-main-Schutz (Opt-out: `.commit-on-main`), Commit-Message-Validierung (Conventional Commits), apt -y Blockade | | `PostToolUse` | Edit / Write | `hooks/auto-format.sh` | `ruff` (Python), `eslint --fix` (JS/TS/Vue) oder `shellcheck` (Bash) | | `Stop` | Session-Ende | `hooks/verify-on-stop.sh` | Uncommittete Änderungen anzeigen | @@ -139,7 +139,7 @@ Kurzbefehl für den gesamten Ablauf: `/story` ## Git-Workflow (Abweichung von globaler CLAUDE.md) -In diesem Repository wird **direkt auf `main` committet** — ohne Feature-Branches und ohne PRs. Die globale Regel „Niemals direkt auf main committen" gilt hier nicht, da es sich um ein Konfigurations-Repo ohne Deployment-Pipeline handelt. +In diesem Repository wird **direkt auf `main` committet** — ohne Feature-Branches und ohne PRs. Die globale Regel „Niemals direkt auf main committen" gilt hier nicht, da es sich um ein Konfigurations-Repo ohne Deployment-Pipeline handelt. Die Datei `.commit-on-main` im Repo-Root signalisiert dem PreToolUse-Hook, den Branch-Schutz zu überspringen. ## Gitea-Integration diff --git a/hooks/pre-bash-checks.sh b/hooks/pre-bash-checks.sh index 9d94e21..329cf0b 100755 --- a/hooks/pre-bash-checks.sh +++ b/hooks/pre-bash-checks.sh @@ -18,9 +18,10 @@ extract_subject() { # Git-Commit-Pruefungen if echo "$cmd" | grep -qE '^\s*git\s+commit\b'; then - # Branch-Schutz: kein direkter Commit auf main + # Branch-Schutz: kein direkter Commit auf main (sofern kein Opt-out per Markerdatei) branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "") - if [ "$branch" = "main" ]; then + repo_root=$(git rev-parse --show-toplevel 2>/dev/null || echo "") + if [ "$branch" = "main" ] && [ ! -f "${repo_root}/.commit-on-main" ]; then printf '{"continue":false,"stopReason":"BLOCKIERT: Direkter Commit auf main verboten (globale Regel). Bitte zuerst Feature-Branch erstellen: git checkout -b session/YYYY-MM-DD-titel"}\n' exit 0 fi