A Go reimplementation of pre-commit — a framework for managing and maintaining multi-language pre-commit hooks.
make build # Build binary to build/pre-commit
make test # Run tests with race detector: go test -v -race ./...
make lint # Run golangci-lint via go tool
make fmt # Format code: gofumpt -w .
make vet # Run go vet
make check # fmt + vet + test
make tidy # go mod tidy- CLI framework:
mitchellh/clifor command dispatch,jessevdk/go-flagsfor flag parsing - Coloring:
charmbracelet/lipglossfor terminal styling - Entry point:
main.go→internal/cli.Run()
| Package | Purpose |
|---|---|
cli |
Command definitions — each command is a struct implementing cli.Command |
config |
YAML config parsing (.pre-commit-config.yaml) |
git |
Git operations (staging, refs, hooks dir) |
hook |
Hook execution engine and runner |
identify |
File type identification by extension, filename, shebang |
languages |
21 language backends (python, node, go, rust, docker, etc.) |
output |
Terminal output formatting with lipgloss styles |
pcre |
PCRE regex support via dlclark/regexp2 |
repository |
Hook repository resolution and caching |
staged |
Stash management for staged files |
store |
On-disk cache for cloned hook repos |
xargs |
Parallel execution with batching |
- Commands use
mitchellh/cli.Commandinterface:Run(args []string) int,Help() string,Synopsis() string - Each command embeds
*Metafor shared state and has a flags struct embeddingGlobalFlags - Flag parsing uses
jessevdk/go-flagsstruct tags - Error output goes to stderr, return
1for failure,0for success - The project mirrors the Python pre-commit CLI interface exactly (drop-in replacement)