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