git-hook-installer-2.0.0 is not a library.
git-hook-installer
A small Rust CLI that installs premade git hooks into the current repository.
Install
From crates.io:
Or from source (this repo):
Usage
Run with no arguments to offer to install/update the managed pre-commit hook:
Inspect the current hook state:
Install/update the managed pre-commit hook directly:
Disable the managed pre-commit block (without removing it):
Uninstall the managed pre-commit block (preserves any other pre-commit logic you already had):
If your repo has multiple Cargo.toml files (monorepo), pick which one the hook should use:
Behavior
- git repo detection: walks up parent directories looking for
.git(supports worktrees where.gitis a file). - safe overwrites: if a hook already exists, it will prompt before backing it up (or use
--force/--yes). - hook installed:
.git/hooks/pre-commitcontains a managed block (marked withgit-hook-installerbegin/end markers) which can run a set of formatters/linters and re-stage changes. - no repo config: all settings are stored inside the hook file in
.git/hooks/(nothing is written to your repository). - toolchain auto-selection: the installer auto-detects the most likely JS/TS, Python, and Java/Kotlin toolchain from common config files (and falls back to sensible defaults). In interactive installs it prints a short “auto-selected/defaulting” summary; in
--non-interactivemode it stays quiet. - auto-fix safety:
- If you have unstaged/untracked changes, the hook stashes them with
git stash push --keep-index --include-untracked, runs auto-fix on the staged files, re-stages, and then restores the stash. - If a formatting step errors, the hook attempts a best-effort rollback (reset + re-apply saved staged diff, plus stash restore if used).
- If you have unstaged/untracked changes, the hook stashes them with
- snapshots before edits: before
git-hook-installermodifies.git/hooks/pre-commit, it snapshots the current file to.git/hooks/pre-commit.snapshot-YYYY-MM-DD-HH-MM-SSand keeps the newest 10 snapshots by default.
Options
-y, --yes: auto-confirm prompts--non-interactive: never prompt (fails on ambiguity or existing hooks unless--force)-f, --force: overwrite existing hook (backs it up first)