Skip to content

Pre-commit hook is very slow to install #4281

@goodspark

Description

@goodspark

Please review the Community Note before submitting

TruffleHog Version

N/A

Trace Output

N/A

Actual Behavior

  1. The hook install took several minutes.

Steps to Reproduce

  1. Add Trufflehog to precommit hook
  2. Run precommit
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions