Skip to main content

git-a-grip

Two things, from one package:

  1. A set of pre-commit hooks you point your .pre-commit-config.yaml at.
  2. gag, a CLI for managing pre-commit across all your repos — see what every project pins, and pin them all to the same rev.

1. The hooks

repos:
  - repo: https://github.com/dannybrown37/git-a-grip
    rev: v0.7.0
    hooks:
      - id: commitizen-early
      - id: ruff-check
      - id: ruff-format
      - id: embed-tree
      - id: embed-command
        args: ['--marker=help', '--command=mytool --help']
      - id: pytest
        args: [tests/, -q]

Nothing to install. Your project needs no ruff, cz or uv on PATH — pre-commit builds the env. (pytest, eslint and tsc are the exceptions: they must run inside your project's environment, so they shell out to uv run / your package manager.)

Hook What it does for you
commitizen-early Rejects a bad commit message in ~0.3s, instead of after the whole hook suite has run. Pair with the upstream commitizen hook for the cases it can't see (editor, merge, rebase).
ruff-check ruff check --fix, with fixes re-staged — no dirty tree to git add and amend.
ruff-format ruff format, likewise re-staged.
pytest Your test suite, from the repo root, in your project's env. args: ['--runner=uv run --extra api pytest', ...] to change the runner.
embed-tree Keeps a file tree in your README true. Drop <!-- tree:start --> / <!-- tree:end --> in, and it regenerates and re-stages on every commit. Contents come from git ls-files, so it's exactly what's committed. (Was readme-tree; the old id still works.)
embed-command Keeps a command's output — mytool --help, make help — true in your README. Name the command in args; nothing is discovered and run on its own.
eslint eslint --fix, re-staged, --max-warnings=0 by default so warnings can't pile up forever. --dir=web for a monorepo.
tsc Type-checks the project, never bare filenames — given filenames, tsc silently ignores your tsconfig.json. --dir=web for a monorepo.

Anything in args is passed through to the underlying tool. Pin your own tool version with additional_dependencies: [ruff==0.16.1].

eslint and tsc run from the repo root unless you pass --dir=. If your JS lives in a subdirectory, its eslint.config.mjs, tsconfig.json and node_modules resolve from there, so name it — and scope the hook to match, since files outside that subdirectory are skipped anyway:

      - id: eslint
        args: [--dir=web]
        files: ^web/
      - id: tsc
        args: [--dir=web]
        files: ^web/

The two embed-* hooks are the exception: their args configure the hook itself (--marker=, --command=, --file=, --depth=, --exit=). One entry per block, each with its own --marker. Scope them with files: so a block that changes twice a year isn't regenerated on every commit.

Full details on any hook, including the paste-ready config block:

gag hooks           # one line per hook
gag hooks pytest    # that one, in full
gag hooks --all

2. The gag CLI

uv tool install git-a-grip    # `gag` on PATH
uvx --from git-a-grip gag    # or one-off

gag --help lists everything; gag <command> --help its options.

gag audit — what does every repo pin?

Walks your project directories, stops at each git working tree, and reports which hooks each one uses and at what rev — labelled (behind), (ahead), (unpinned) against the version you have installed. Third-party hooks and repo: local one-offs are listed too.

gag audit
gag audit ~/projects ~/work
gag audit --json | jq '.repos[] | select(.hooks == [])'

gag sync — pin them all to one rev

The other half. Dry run by default, one line per repo (old -> new).

gag sync                    # dry run against the installed version
gag sync --write            # apply it
gag sync --to v0.5.0
gag sync --latest --write
gag sync --repo https://github.com/gitleaks/gitleaks --latest

The rewrite is textual and touches only the rev: line, so your comments and formatting survive. Nothing is committed — changes land in each repo's working tree for you to review.

gag hooks — the hook reference

The table above, in full, from your installed version. Colorized for the terminal, plain when piped. The block below is this repo's own embed-command hook keeping gag hooks output honest:

git-a-grip 0.6.0 -- pre-commit hooks

Turn one on in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/dannybrown37/git-a-grip
    rev: v0.7.0
    hooks:
      - id: <one of the below>
      - id: <...any number of others>

  commitizen-early  Reject a bad commit message before the slow hooks run.
  embed-command     Keep a command's output (`--help`) true in the README.
  embed-tree        Regenerate the README file tree, and re-stage it.
  eslint            Lint with the project's own eslint, re-staging fixes.
  pytest            Run the repo's tests through its own environment.
  ruff-check        Lint with `ruff check --fix`, re-staging what it fixed.
  ruff-format       Format with `ruff format`, re-staging what it rewrote.
  tsc               Type-check the project with the project's own tsc.

gag hooks <id> for one in full, gag hooks --all for all of them.

Running a hook by hand

The hooks aren't scripts on your PATH — gag is the only thing this package installs. To run one outside pre-commit (debugging):

uv tool install 'git-a-grip[hooks]'
python -m git_a_grip.hooks ruff-check path/to/file.py

Development

uv sync
uv run pytest

Releases are cut by CI: merge to main, and if lint, tests and the install proofs pass, cz bump tags it and publish.yml uploads to PyPI. Nothing is tagged before the checks pass.

This repo eats its own dog food — its hooks run on itself, and the tree below is maintained by embed-tree.

git-a-grip/
|-- .github/
|   `-- workflows/
|       |-- ci.yml
|       `-- publish.yml
|-- src/
|   `-- git_a_grip/
|       |-- __init__.py
|       |-- audit.py
|       |-- cli.py
|       |-- commitizen_early.py
|       |-- cz.py
|       |-- doc_block.py
|       |-- embed_command.py
|       |-- embed_tree.py
|       |-- hook_docs.py
|       |-- hooks.py
|       |-- node_hooks.py
|       |-- pytest_hook.py
|       |-- restage.py
|       |-- ruff_hooks.py
|       |-- sync.py
|       `-- version.py
|-- tests/
|   |-- test_audit.py
|   |-- test_cli.py
|   |-- test_commitizen_early.py
|   |-- test_doc_block.py
|   |-- test_embed_command.py
|   |-- test_embed_tree.py
|   |-- test_hook_docs.py
|   |-- test_hooks.py
|   |-- test_node_hooks.py
|   |-- test_packaging.py
|   |-- test_pytest_hook.py
|   |-- test_restage.py
|   |-- test_ruff_hooks.py
|   |-- test_sync.py
|   `-- test_version.py
|-- .gitignore
|-- .pre-commit-config.yaml
|-- .pre-commit-hooks.yaml
|-- .ruff.toml
|-- CHANGELOG.md
|-- CLAUDE.md
|-- LICENSE
|-- pyproject.toml
|-- README.md
`-- uv.lock

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_a_grip-0.7.0.tar.gz (79.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_a_grip-0.7.0-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file git_a_grip-0.7.0.tar.gz.

File metadata

  • Download URL: git_a_grip-0.7.0.tar.gz
  • Upload date:
  • Size: 79.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for git_a_grip-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7196d372df8b1ae70f933d723ac1e6debed3a4abf711da285ccd8c06102e2b1f
MD5 437d3faf72247556d8c6d56e4df124f8
BLAKE2b-256 75b112c47aad8e10574afde3de4b5f39ce52b23f81508a2afc8c9cc2c5bbea31

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_a_grip-0.7.0.tar.gz:

Publisher: publish.yml on dannybrown37/git-a-grip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file git_a_grip-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: git_a_grip-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for git_a_grip-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8445c010a565a3f0e64f29d1a3cb8f56ea90c1924c1787de2c96fb8761a744b7
MD5 b3cb39220e0cd14503506a1b21e0f642
BLAKE2b-256 88d740011e103e8c1d790be5299fcd6332b38fb70d65cfa7901790a8e8e22c1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_a_grip-0.7.0-py3-none-any.whl:

Publisher: publish.yml on dannybrown37/git-a-grip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page