From 66bc47bf50ea8d0f2dd2b954cf8ef92353139329 Mon Sep 17 00:00:00 2001 From: KeviM Date: Wed, 13 May 2026 08:56:15 -0700 Subject: [PATCH] chore(make): add pre-commit + install-hooks targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the kalshi-cpp Makefile pattern. Eliminates the recurring "push -> CI clang-format/cpp_auto_audit fail -> follow-up fix PR" loop by making the lint+format check trivially runnable before every commit. - `make pre-commit` runs `format` then `lint` - `make install-hooks` drops .git/hooks/pre-commit that fires `make pre-commit` on every `git commit`. Idempotent. Pre-commit hook is opt-in (one-shot operator setup) and CI gates are unchanged — this is pure local DX. --- Makefile | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3ed52eb..20f17ea 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CMAKE := cmake NPROC := $(shell nproc 2>/dev/null || echo 4) BENCH_ITERATIONS := 254 -.PHONY: all build debug test lint clean configure help bench format coverage \ +.PHONY: all build debug test lint clean configure help bench format pre-commit install-hooks coverage \ run-basic_cdo_usage run-historical_temperature run-multi_year_data run-format_comparison run-data_service_search # Default target @@ -71,6 +71,23 @@ coverage: @genhtml build-coverage/coverage_filtered.info --output-directory build-coverage/coverage-report @echo "Coverage report: build-coverage/coverage-report/index.html" +# pre-commit: auto-format, then lint. Run before every commit to avoid +# the recurring "push -> CI clang-format/auto-audit fail -> follow-up fix +# PR" loop. Idempotent — `format` re-running is a no-op. +pre-commit: format lint + +# install-hooks: drop a .git/hooks/pre-commit shim that runs `make pre-commit` +# on every `git commit`. One-shot operator setup; idempotent. +install-hooks: + @mkdir -p .git/hooks + @if [ -f .git/hooks/pre-commit ] && grep -q 'make pre-commit' .git/hooks/pre-commit 2>/dev/null; then \ + echo "pre-commit hook already installed"; \ + else \ + printf '#!/bin/sh\nexec make pre-commit\n' > .git/hooks/pre-commit; \ + chmod +x .git/hooks/pre-commit; \ + echo "Installed .git/hooks/pre-commit -> make pre-commit"; \ + fi + # Clean build artifacts clean: @rm -rf $(BUILD_DIR) build-coverage