fix(consistency): prevent post-commit hook re-entrancy loop

The post-commit hook re-invokes fix-consistency, which commits writeback
changes, which re-triggers the hook — causing exponential process spawning.

Fix: pass GIT_CUSTODIAN_SYNC=1 in the env for all writeback git commits.
Update the post-commit hook (not tracked by git) to exit early when this
variable is set.

Also remove the --no-verify flag that was added as a failed attempt (it
only skips pre-commit/commit-msg, not post-commit hooks).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-28 23:48:14 +01:00
parent 1f8ef7f88b
commit a486c63603

View File

@@ -922,14 +922,18 @@ def _git_commit_writeback(
f"Updated by fix-consistency on {_date.today().isoformat()}:\n"
f"{summary}"
)
import os as _os
# Pass GIT_CUSTODIAN_SYNC=1 so the post-commit hook can detect it is
# running from within a sync pass and exit early, preventing re-entrancy.
sync_env = {**_os.environ, "GIT_CUSTODIAN_SYNC": "1"}
try:
subprocess.run(
["git", "-C", repo_path, "add", str(file_path)],
check=True, capture_output=True,
check=True, capture_output=True, env=sync_env,
)
subprocess.run(
["git", "-C", repo_path, "commit", "-m", msg],
check=True, capture_output=True,
check=True, capture_output=True, env=sync_env,
)
return True
except subprocess.CalledProcessError as e: