git-hook-installer 2.0.0

Install basic premade git hooks into the current repository.
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.

crates.io License: MIT Repository

Install

From crates.io:

cargo install git-hook-installer

Or from source (this repo):

cargo install --path .

Usage

Run with no arguments to offer to install/update the managed pre-commit hook:

git-hook-installer

Inspect the current hook state:

git-hook-installer status

Install/update the managed pre-commit hook directly:

git-hook-installer install pre-commit

Disable the managed pre-commit block (without removing it):

git-hook-installer disable

Uninstall the managed pre-commit block (preserves any other pre-commit logic you already had):

git-hook-installer uninstall

If your repo has multiple Cargo.toml files (monorepo), pick which one the hook should use:

git-hook-installer install pre-commit --manifest-dir crates/my-crate

Behavior

  • git repo detection: walks up parent directories looking for .git (supports worktrees where .git is 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-commit contains a managed block (marked with git-hook-installer begin/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-interactive mode 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).
  • snapshots before edits: before git-hook-installer modifies .git/hooks/pre-commit, it snapshots the current file to .git/hooks/pre-commit.snapshot-YYYY-MM-DD-HH-MM-SS and 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)

Links