Files
fn_registry/bash/functions/infra/pre_commit_hook_install.md
T
egutierrez cfdf515228 chore: auto-commit (799 archivos)
- .claude/CLAUDE.md
- .claude/commands/subagentes.md
- .claude/rules/INDEX.md
- .mcp.json
- bash/functions/cybersecurity/analyze_dns.md
- bash/functions/cybersecurity/audit_http_headers.md
- bash/functions/cybersecurity/audit_ssh_config.md
- bash/functions/cybersecurity/check_firewall.md
- bash/functions/cybersecurity/detect_suspicious_users.md
- bash/functions/cybersecurity/encrypt_file.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 00:28:20 +02:00

2.7 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
pre_commit_hook_install function bash infra 1.0.0 impure pre_commit_hook_install(repo_dir: string, [--force]) -> void Instala un hook pre-commit en .git/hooks/pre-commit de un repo dado. El hook invoca scan_secrets_in_dirty para abortar el commit si detecta secrets en archivos staged. Idempotente: si el hook ya esta instalado (marca fn_registry-pre-commit-v1) no lo sobreescribe a menos que se pase --force.
git
hook
precommit
secrets
pendiente-usar
scan_secrets_in_dirty_bash_cybersecurity
false error_go_core
name desc
repo_dir Ruta al directorio raiz del repo Git (debe contener .git/hooks/).
name desc
--force Flag opcional. Si se pasa, sobreescribe el hook aunque ya exista (hace backup con timestamp).
Imprime INSTALLED <path> o SKIP <path> (already installed). Retorna exit code 1 si repo_dir no es un repo git valido, 2 si el hook existe y no es nuestro sin --force. false
bash/functions/infra/pre_commit_hook_install.sh

Ejemplo

source bash/functions/infra/pre_commit_hook_install.sh

# Instalar en el repo actual
pre_commit_hook_install /home/lucas/fn_registry
# INSTALLED /home/lucas/fn_registry/.git/hooks/pre-commit

# Idempotente: segunda llamada no sobreescribe
pre_commit_hook_install /home/lucas/fn_registry
# SKIP /home/lucas/fn_registry/.git/hooks/pre-commit (already installed)

# Forzar reinstalacion (hace backup del hook anterior)
pre_commit_hook_install /home/lucas/fn_registry --force
# INSTALLED /home/lucas/fn_registry/.git/hooks/pre-commit

Notas

Idempotente por diseno: la marca # fn_registry-pre-commit-v1 en el hook generado sirve como identificador. Si el hook existe y tiene la marca, la funcion no sobreescribe a menos que se pase --force.

Si el hook existe pero NO tiene la marca (es un hook ajeno), la funcion falla con exit 2 y un mensaje de error claro. Con --force, se hace backup a pre-commit.bak.<timestamp> antes de reescribir.

El hook generado localiza fn_registry en dos pasos:

  1. La variable de entorno FN_REGISTRY_ROOT si esta definida.
  2. Si el repo donde se hace commit tiene registry.db en la raiz, asume que el propio repo es fn_registry.

Si no puede localizar fn_registry, el hook imprime un aviso y sale con exit 0 (no bloquea el commit). Esto permite instalar el hook en repos externos al registry sin romper su flujo.

Configurar FN_REGISTRY_ROOT en el perfil del shell para garantizar que el hook siempre encuentre el registry:

export FN_REGISTRY_ROOT=/home/lucas/fn_registry