-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Please review the Community Note before submitting
TruffleHog Version
N/A
Trace Output
N/A
Actual Behavior
- The hook install took several minutes.
Steps to Reproduce
- Add Trufflehog to precommit hook
- Run precommit
- Notice how much time it takes to install the hook
Environment
- OS: macOS
- Version 15.5
Additional Context
The key issue is that the precommit hook is setup as a golang hook. When precommit sees this, it will try to clone the repo and build the binary from scratch. And that's the part that takes a long time. This unfortunately disincentivizes Trufflehog upgrades, because it causes so much developer pain.
https://pre-commit.com/#golang
The hook repository must contain go source code. It will be installed via go install ./.... pre-commit will create an isolated GOPATH for each hook and the entry should match an executable which will get installed into the GOPATH's bin directory.
Since the Trufflehog team already releases precompiled binaries, a faster approach could be to use the 'script' or 'system' language and then write a simple script that downloads the appropriate binary for the host OS/arch and then run that. I'd imagine that'll be much faster.
uv/Ruff does something slightly similar, although with one more step. They use maturin to publish Python packages that simply wrap around their compiled binaries. And their precommit hooks are very similar - they themselves are Python projects that only install specific versions of their Python package. While there are a few steps to this and some that don't strictly apply to Golang, the idea is roughly similar.