|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # |
3 | 3 | # metaobjects is a PUBLIC repository. |
4 | | -# Block commits that leak private/other-project names or absolute local paths. |
5 | | -# See CLAUDE.md -> "Public repository hygiene". |
| 4 | +# Block commits that leak absolute local paths, or private/other-project names. |
| 5 | +# |
| 6 | +# IMPORTANT: this committed hook names NO private project. The structural |
| 7 | +# patterns below are generic (home paths). Private project names live ONLY in an |
| 8 | +# UNTRACKED local denylist so the guard itself never becomes a leak: |
| 9 | +# |
| 10 | +# .githooks/deny-list.local (gitignored; one regex per line; you create it) |
| 11 | +# .githooks/deny-list.example (committed template, placeholders only) |
6 | 12 | # |
7 | 13 | # Activate (one-time, per clone): git config core.hooksPath .githooks |
| 14 | +# cp .githooks/deny-list.example .githooks/deny-list.local |
| 15 | +# # then edit deny-list.local with the real names |
8 | 16 | # Bypass (discouraged): git commit --no-verify |
9 | 17 | # |
10 | 18 | set -uo pipefail |
11 | 19 |
|
12 | | -# Case-insensitive forbidden patterns. Keep in sync with CLAUDE.md. |
13 | | -# - other/private project names (and known abbreviations/derivations) |
14 | | -# - absolute local paths that leak a developer's home directory |
15 | | -# NOTES: |
16 | | -# - matches the separate "sibling-ai-project" project, NOT bare "draagon" — "com.draagon.meta" |
17 | | -# is this project's own legacy package namespace and is legitimate. |
18 | | -# - "trainer-website" is an accepted example-consumer name and is intentionally NOT guarded; |
19 | | -# "downstream-consumer" / "@acme/" / "acme" (a private consumer) ARE guarded. |
20 | | -PATTERNS='party-?lore|sibling-app|acme-?website|\bmikes\b|@acme/|acme|sibling-ai-project|csharp-adopter|sibling-project|/home/[A-Za-z0-9._-]+/|~/Development' |
| 20 | +# Generic, non-sensitive structural patterns — safe to commit (name no project): |
| 21 | +PATTERNS='/home/[A-Za-z0-9._-]+/|~/Development' |
21 | 22 |
|
22 | 23 | # Legitimate matches to ignore (e.g. the published npm author email). |
23 | 24 | ALLOW='doug@dougmealing\.com' |
24 | 25 |
|
25 | | -# Scan only newly-ADDED staged lines, attributed to their file. |
| 26 | +# Merge in private-name patterns from the untracked local denylist, if present. |
| 27 | +ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" |
| 28 | +DENY_FILE="$ROOT/.githooks/deny-list.local" |
| 29 | +if [ -f "$DENY_FILE" ]; then |
| 30 | + extra=$(grep -vE '^[[:space:]]*(#|$)' "$DENY_FILE" | paste -sd'|' -) |
| 31 | + [ -n "$extra" ] && PATTERNS="$PATTERNS|$extra" |
| 32 | +fi |
| 33 | + |
| 34 | +# Scan only newly-ADDED staged lines, attributed to their file; skip the hooks dir. |
26 | 35 | hits=$(git diff --cached --diff-filter=ACM -U0 --no-color 2>/dev/null | awk ' |
27 | 36 | /^\+\+\+ / { f=$2; sub(/^b\//,"",f); next } |
28 | | - # skip the hook itself (its PATTERNS line legitimately lists the forbidden words) |
29 | 37 | /^\+/ && !/^\+\+\+/ { if (f !~ /^\.githooks\//) print f "\t" substr($0,2) } |
30 | 38 | ' | grep -Ei "$PATTERNS" | grep -vEi "$ALLOW") |
31 | 39 |
|
|
0 commit comments