fix(gitflow): pre-commit exempts only .claude memory, tasks, audits, deploy

Any .claude/** set passed on main/develop, rules and settings included, and a git mv hid its source. The hook now allowlists the side-car dirs and lists with --no-renames; both hook copies regenerated, citers reworded.
This commit is contained in:
bchanot committed 2026-11-06 17:13:58 +01:00
1 parent 97c6afcbc8
commit c5bd0f8312
7 files changed
+51 -21

No files matched your search

+6 -4
View File
@@ -34,13 +34,15 @@ case "$br" in
*) exit 0 ;; # working branch — allow *) exit 0 ;; # working branch — allow
esac esac
# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or # whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or
# .githooks/ (the hooks themselves, refreshed by the lib) — allow # .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules,
if [ -z "$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then # settings, agents, skills stay blocked. --no-renames lists a rename's source
# too, so a git mv out of a blocked path cannot hide.
if [ -z "$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then
exit 0 exit 0
fi fi
echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2 echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2
echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2
echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2
exit 1 exit 1
+6 -5
View File
@@ -157,8 +157,9 @@ open release; prod incidents only, a small fix on develop is a `bugfix`).
`master` → `main` everywhere. `master` → `main` everywhere.
Never commit code on `main` or `develop`: branch first as `<type>/<name>` Never commit code on `main` or `develop`: branch first as `<type>/<name>`
(a `.claude/**` memory/config commit that follows merged work is hook-exempt (a commit under the `.claude/{memory,tasks,audits,deploy}/` allowlist that
and lands in place; a standalone memory task branches `chore/*`). follows merged work is hook-exempt and lands in place; a standalone memory
task branches `chore/*`).
Branch, merge and delete only via the lib: `bash ~/.claude/lib/gitflow.sh Branch, merge and delete only via the lib: `bash ~/.claude/lib/gitflow.sh
start <type> <name>` · `finish` · `delete <br>`. `finish` runs only on an start <type> <name>` · `finish` · `delete <br>`. `finish` runs only on an
explicit human signal ("merge it", "feature OK"), never because tests pass, explicit human signal ("merge it", "feature OK"), never because tests pass,
@@ -169,10 +170,10 @@ Assistance flows (`/feat`
protected base but commit in place on a working branch, never finishing protected base but commit in place on a working branch, never finishing
(one exception, BDR-068: `/capitalize` and `/close` auto-finish the (one exception, BDR-068: `/capitalize` and `/close` auto-finish the
memory-only `chore/*` they created this run), so they branch to `chore/*` memory-only `chore/*` they created this run), so they branch to `chore/*`
via the aiguillage, not the `.claude/**` exemption. via the aiguillage, not the hook allowlist.
Deterministic backstops behind the doctrine: the pre-commit hook (blocks Deterministic backstops behind the doctrine: the pre-commit hook (blocks
code commits on main/develop; exempts `.claude/**`, `.githooks/**`, merges, code commits on main/develop; exempts the `.claude/{memory,tasks,audits,
the root commit), Gitea branch protection on both, and never `--no-verify`. deploy}/` allowlist, `.githooks/`, merges, the root commit), Gitea branch protection on both, and never `--no-verify`.
Every branch is pushed at `start`, every commit and merge as it lands Every branch is pushed at `start`, every commit and merge as it lands
(post-commit and post-merge hooks; warn, never block). A branch is deleted (post-commit and post-merge hooks; warn, never block). A branch is deleted
only by `finish` or `delete`, local and `origin/` copy alike: never only by `finish` or `delete`, local and `origin/` copy alike: never
+6 -4
View File
@@ -34,13 +34,15 @@ case "$br" in
*) exit 0 ;; # working branch — allow *) exit 0 ;; # working branch — allow
esac esac
# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or # whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or
# .githooks/ (the hooks themselves, refreshed by the lib) — allow # .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules,
if [ -z "$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then # settings, agents, skills stay blocked. --no-renames lists a rename's source
# too, so a git mv out of a blocked path cannot hide.
if [ -z "$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then
exit 0 exit 0
fi fi
echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2 echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2
echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2
echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2
exit 1 exit 1
+2 -2
View File
@@ -32,8 +32,8 @@ doc reconciliation & curation skills (+ `/refactor`), run OUTSIDE an assistance
`/bugfix` `/hotfix` `/ship-feature` a working branch already exists (this check `/bugfix` `/hotfix` `/ship-feature` a working branch already exists (this check
returns WORKING) and the memory commit rides it. The aiguillage only fires when returns WORKING) and the memory commit rides it. The aiguillage only fires when
such a skill is invoked directly on `main`/`develop` — i.e. memory IS the work, such a skill is invoked directly on `main`/`develop` — i.e. memory IS the work,
with no code branch to follow. That is the leak it closes: the `.claude/**` hook with no code branch to follow. That is the leak it closes: the `.claude/` allowlist hook exemption
exemption still lets a *manual* memory commit through on a protected base, but a still lets a *manual* memory commit through on a protected base, but a
skill-driven one now branches to `chore/*` first. skill-driven one now branches to `chore/*` first.
**Integration is human-gated by default** — these flows commit, they do not merge. **Integration is human-gated by default** — these flows commit, they do not merge.
+24 -1
View File
@@ -89,7 +89,7 @@ echo x >> README.md; git add README.md
chk "block direct code on main" '! git commit -q -m onmain 2>/dev/null' chk "block direct code on main" '! git commit -q -m onmain 2>/dev/null'
git restore --staged README.md 2>/dev/null; git checkout -q -- README.md git restore --staged README.md 2>/dev/null; git checkout -q -- README.md
mkdir -p .claude/memory; echo m > .claude/memory/decisions.md; git add .claude/memory/decisions.md mkdir -p .claude/memory; echo m > .claude/memory/decisions.md; git add .claude/memory/decisions.md
chk "allow .claude/** on main" 'git commit -q -m "chore(memory)" 2>/dev/null' chk "allow .claude/memory on main" 'git commit -q -m "chore(memory)" 2>/dev/null'
gitflow_start feature demo >/dev/null 2>&1 gitflow_start feature demo >/dev/null 2>&1
echo f > feat.txt; git add feat.txt echo f > feat.txt; git add feat.txt
chk "allow code on feature" 'git commit -q -m "feat work" 2>/dev/null' chk "allow code on feature" 'git commit -q -m "feat work" 2>/dev/null'
@@ -474,6 +474,29 @@ git config gitflow.protect false
chk "T21c gitflow.protect=false → allowed" '.githooks/pre-commit 2>/dev/null' chk "T21c gitflow.protect=false → allowed" '.githooks/pre-commit 2>/dev/null'
git config --unset gitflow.protect git config --unset gitflow.protect
git restore --staged code.txt .githooks/post-merge 2>/dev/null || true git restore --staged code.txt .githooks/post-merge 2>/dev/null || true
git reset -q; rm -f code.txt
# allowlist (memory, tasks, audits, deploy, .githooks): any other .claude/ path blocks
mkdir -p .claude/rules .claude/tasks .claude/memory .claude/audits .claude/deploy
echo r > .claude/rules/x.md; echo '{}' > .claude/settings.json
git add .claude/rules/x.md; git -c core.hooksPath=/dev/null commit -q -m "seed rules"
echo r2 >> .claude/rules/x.md; git add .claude/rules/x.md
chk "T21d .claude/rules-only on develop → blocked" '! .githooks/pre-commit 2>/dev/null'
git reset -q; git checkout -q -- .claude/rules/x.md
git add .claude/settings.json
chk "T21e .claude/settings.json-only on develop → blocked" '! .githooks/pre-commit 2>/dev/null'
git reset -q
git mv .claude/rules/x.md .claude/tasks/x.md
chk "T21f rename rules→tasks on develop → blocked (--no-renames)" '! .githooks/pre-commit 2>/dev/null'
git reset -q --hard
for d in memory tasks audits deploy; do
echo "$d" > ".claude/$d/n.md"; git add ".claude/$d/n.md"
chk "T21g .claude/$d-only on develop → allowed" '.githooks/pre-commit 2>/dev/null'
git reset -q
done
echo m > .claude/memory/n.md; echo r3 >> .claude/rules/x.md
git add .claude/memory/n.md .claude/rules/x.md
chk "T21h memory + rules mix on develop → blocked" '! .githooks/pre-commit 2>/dev/null'
git reset -q --hard
echo "T22 — delete guard: never main/develop, never unmerged (premise: -d is dead once the upstream is in sync)" echo "T22 — delete guard: never main/develop, never unmerged (premise: -d is dead once the upstream is in sync)"
newrepo delguard; echo a>a; hookon; gitflow_init >/dev/null 2>&1 newrepo delguard; echo a>a; hookon; gitflow_init >/dev/null 2>&1
+6 -4
View File
@@ -485,15 +485,17 @@ case "\$br" in
*) exit 0 ;; # working branch — allow *) exit 0 ;; # working branch — allow
esac esac
# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or # whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or
# .githooks/ (the hooks themselves, refreshed by the lib) — allow # .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules,
if [ -z "\$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then # settings, agents, skills stay blocked. --no-renames lists a rename's source
# too, so a git mv out of a blocked path cannot hide.
if [ -z "\$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then
exit 0 exit 0
fi fi
echo "gitflow pre-commit: BLOCKED — direct commit on '\$br'." >&2 echo "gitflow pre-commit: BLOCKED — direct commit on '\$br'." >&2
echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2
echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2
exit 1 exit 1
HOOK HOOK
} }
+1 -1
View File
@@ -605,7 +605,7 @@
"**Repository visibility**: private. The Gitea instance is self-hosted and not publicly indexed, and a checkout with no remote is local-only. Treat every repo here as private unless its remote points at a public host.", "**Repository visibility**: private. The Gitea instance is self-hosted and not publicly indexed, and a checkout with no remote is local-only. Treat every repo here as private unless its remote points at a public host.",
"**Trusted repo**: the checkout Claude Code is currently working in, under `/home/bchanot/Documents/`. No single repo is privileged over the others — read the current one, do not assume a previous session's project.", "**Trusted repo**: the checkout Claude Code is currently working in, under `/home/bchanot/Documents/`. No single repo is privileged over the others — read the current one, do not assume a previous session's project.",
"**Trusted internal domains**: `git.bchanot.fr` (self-hosted Gitea). It is the only internal service.", "**Trusted internal domains**: `git.bchanot.fr` (self-hosted Gitea). It is the only internal service.",
"**Default / protected branches**: gitflow. `main` (prod) and `develop` (integration) are protected: a per-repo pre-commit hook refuses code commits on either (exempting `.claude/**` and merges) and Gitea enforces branch protection on both. Neither is ever deleted or renamed: a reference-transaction hook vetoes it at the ref layer, and a working branch is deleted only by `gitflow.sh finish` or `gitflow.sh delete` after an explicit merged-into-develop-or-main check, the `origin/` copy going with it under the same check on its tip. Work lands on `feature/*`, `bugfix/*`, `chore/*`, `release/*`, `hotfix/*`.", "**Default / protected branches**: gitflow. `main` (prod) and `develop` (integration) are protected: a per-repo pre-commit hook refuses code commits on either (exempting the `.claude/{memory,tasks,audits,deploy}/` allowlist and merges) and Gitea enforces branch protection on both. Neither is ever deleted or renamed: a reference-transaction hook vetoes it at the ref layer, and a working branch is deleted only by `gitflow.sh finish` or `gitflow.sh delete` after an explicit merged-into-develop-or-main check, the `origin/` copy going with it under the same check on its tip. Work lands on `feature/*`, `bugfix/*`, `chore/*`, `release/*`, `hotfix/*`.",
"**Secrets management**: `~/.claude/.env` is the single source of truth and lives outside every git tree; repos reach it through a gitignored symlink. Only `.env.example`, holding placeholders, is ever tracked. A real secret inside a repo is a defect, not a configuration.", "**Secrets management**: `~/.claude/.env` is the single source of truth and lives outside every git tree; repos reach it through a gitignored symlink. Only `.env.example`, holding placeholders, is ever tracked. A real secret inside a repo is a defect, not a configuration.",
"**Internal sharing / snippet hosting**: none. Public paste, gist and pastebin services are outside the trust boundary.", "**Internal sharing / snippet hosting**: none. Public paste, gist and pastebin services are outside the trust boundary.",
"**CI/CD deploy targets**: no CI system. Deploys run out of band by the user, from a per-project runbook that Claude writes or explains (typically lftp/FTP to OVH mutualised hosting for web projects). Claude never runs a deploy or a transfer tool; nothing deploys automatically on a push or a merge.", "**CI/CD deploy targets**: no CI system. Deploys run out of band by the user, from a per-project runbook that Claude writes or explains (typically lftp/FTP to OVH mutualised hosting for web projects). Claude never runs a deploy or a transfer tool; nothing deploys automatically on a push or a merge.",