| Status | Active |
|---|---|
| Owner | HyperFleet Platform Team |
| Last Updated | 2026-04-27 |
Setup, configuration, and usage guide for HyperFleet's centralized pre-commit hooks. Covers installation, project-specific configurations, and migration steps for adding hooks to existing repositories.
- Overview
- Prerequisites
- Available Hooks
- Standard Configuration
- Migration Guide
- Troubleshooting
- References
HyperFleet uses a centralized hook registry at hyperfleet-hooks to enforce consistent commit message format and code quality across all repositories. The pre-commit framework automatically downloads, builds, and caches hook binaries — no manual installation of individual tools is required.
hyperfleet-hooks repository (centralized)
├── .pre-commit-hooks.yaml # Hook definitions
├── cmd/ # commitlint Go binary
└── docs/ # Hook documentation
▼ consumed by pre-commit framework ▼
Any HyperFleet repository (consumer)
├── .pre-commit-config.yaml # Selects which hooks to use
└── Makefile # install-hooks target
When a developer runs git commit, the pre-commit framework intercepts the operation, runs the configured hooks, and blocks the commit if any hook fails. This provides immediate feedback before code reaches CI.
-
pre-commit installed:
pip install pre-commit
-
Go 1.25+ (for the
commitlinthook — built automatically by pre-commit on first run) -
maketargets (lint,gofmt,go-vet) in the consuming repo (for Go tooling hooks)
All hooks are defined in the hyperfleet-hooks repository:
| Hook ID | Stage | Language | Description |
|---|---|---|---|
hyperfleet-commitlint |
commit-msg |
golang |
Validates commit messages against the HyperFleet Commit Standard |
hyperfleet-golangci-lint |
pre-commit |
system |
Runs make lint — delegates to the repo's bingo-managed golangci-lint |
hyperfleet-gofmt |
pre-commit |
system |
Runs make gofmt — checks Go file formatting |
hyperfleet-go-vet |
pre-commit |
system |
Runs make go-vet — finds suspicious constructs in Go code |
The Go tooling hooks use language: system and delegate to existing Make targets rather than reimplementing tool resolution. This leverages each repo's bingo-managed tool versions (see dependency pinning standard).
All HyperFleet repositories SHOULD use the same .pre-commit-config.yaml. The Go tooling hooks (gofmt, golangci-lint, go-vet) use types: [go] filtering, so they only trigger when Go files are staged — in non-Go repos they are simply skipped.
# .pre-commit-config.yaml
# Installs both pre-commit and commit-msg hooks with a single `pre-commit install`
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/openshift-hyperfleet/hyperfleet-hooks
rev: v0.1.1 # pin to a specific tag
hooks:
- id: hyperfleet-commitlint
stages: [commit-msg]
- id: hyperfleet-gofmt
- id: hyperfleet-golangci-lint
- id: hyperfleet-go-vet
# File hygiene
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-filesThe file hygiene hooks (trailing-whitespace, end-of-file-fixer, check-added-large-files) catch common issues — trailing whitespace, missing final newlines, and accidentally committed large binaries — before they reach PR review.
Note:
default_install_hook_types: [pre-commit, commit-msg]means a singlepre-commit installcommand installs hooks for both thepre-commitandcommit-msgstages. Without this setting, you would need to runpre-commit install --hook-type commit-msgseparately to enable commit message validation.
Follow these steps to add pre-commit hooks to an existing HyperFleet repository.
Copy the Standard Configuration into a .pre-commit-config.yaml file in the repo root.
Add the target to your Makefile (see Makefile Conventions — Optional Targets):
.PHONY: install-hooks
install-hooks: ## Install pre-commit hooks
pre-commit installThe Go tooling hooks expect make gofmt and make go-vet targets. If your repo uses different names (e.g., fmt and vet), add aliases:
.PHONY: gofmt
gofmt: fmt ## Alias for fmt
.PHONY: go-vet
go-vet: vet ## Alias for vetAdd pre-commit to the prerequisites section in your README.md:
### Prerequisites
- Go 1.25 or later
- Docker or Podman
- Make
- pre-commitAdd the hook installation step to your getting started section or CONTRIBUTING.md:
### Getting Started
# ... existing steps ...
# Install git hooks
make install-hooksmake install-hooksTest with valid commits (both formats are accepted):
git commit --allow-empty -m "test: verify pre-commit hooks"
git commit --allow-empty -m "HYPERFLEET-XXX - test: verify pre-commit hooks"Test with an invalid commit (should fail):
git commit --allow-empty -m "bad commit message"Run hooks against the entire codebase to fix any pre-existing violations (trailing whitespace, missing EOF newlines, etc.). Without this step, the first contributor who touches an unrelated file with a trailing whitespace or missing newline gets a hook failure they didn't cause.
pre-commit run --all-filesReview auto-fixes, stage them, and commit as a separate companion PR so the cleanup doesn't muddy the diff of the hook configuration PR:
git add -p
git commit -m "HYPERFLEET-XXX - chore: fix pre-commit baseline violations"git add .pre-commit-config.yaml Makefile README.md CONTRIBUTING.md
git commit -m "HYPERFLEET-XXX - chore: add pre-commit hooks"Install the pre-commit framework:
pip install pre-commitOr via Homebrew on macOS:
brew install pre-commitYour Makefile needs the gofmt alias. Add it pointing to your existing formatting target:
.PHONY: gofmt
gofmt: fmt ## Alias for fmtPre-commit caches hook environments. Clear the cache and reinstall:
pre-commit clean
pre-commit installIn rare cases (e.g., merge commits), you can skip hooks:
git commit --no-verify -m "HYPERFLEET-123 - chore: merge conflict resolution"Use this sparingly — CI will still validate the commit message on the PR.
To pull the latest hook definitions:
pre-commit autoupdateThis updates the rev field in .pre-commit-config.yaml to the latest tag.
- Commit Standard — commit message format enforced by
hyperfleet-commitlint - Makefile Conventions —
install-hooks,gofmt, andgo-vetoptional targets - Dependency Pinning — bingo-managed tool versions used by Go hooks
- Linting Standard — golangci-lint configuration
- pre-commit documentation
- hyperfleet-hooks repository
- Sentinel pilot PR (hyperfleet-sentinel#102) — reference implementation