r/git • • 11d ago

Goat Hooker: Git hooks that skip what didn't change. Feedback welcome

Post image

I got tired of pre-commit hooks re-running the same 10 seconds of checks every time a commit message got rejected, and of mono-repos where every hook runs on every project. So I wrote Goat Hooker, a Git hooks manager in Rust.

What it does differently:

  • Only what changed. Each hook runs on the staged files it targets, and a hook whose files didn't change since it last passed is skipped. Retrying a commit with 5 hooks takes ~24 ms instead of re-running them.
  • Sees exactly what you commit. Unstaged changes are put aside while hooks run, and files fixed by formatters are staged again.
  • Mono-repos. Each project has its own hooker.config.json. Dependencies are read from Cargo / package.json / go.mod, so changing core also runs the tests of api.
  • Hooks can depend on each other and pass values. For example, a codegen hook hands its output to a lint hook.
  • hooker watch runs the hooks while you stage, so git commit itself is instant.
  • hooker import converts husky / lint-staged, lefthook and pre-commit configs.
  • There's also a desktop app if you'd rather click than edit JSON.

I benchmarked a git commit against lefthook, pre-commit and husky + lint-staged. With one no-op hook, the overhead is about the same as lefthook (30 ms vs 28 ms). It's well below pre-commit (146 ms) and husky + lint-staged (395 ms). The method is in the repo if you want to check it.

It's pre-1.0, so the config may still change. I'd love feedback on what breaks in your workflow, or what your current hooks manager does badly.

Repo: https://github.com/zuygui/goat-hooker

If you find it useful, a ⭐ on GitHub helps a lot: it's how a small project like this gets noticed.

(Yes, I know about the name.)

0 Upvotes

0 comments sorted by