Added pre commit hooks

This commit is contained in:
Waldemar Kindler 2026-01-05 15:00:09 +01:00
parent f79975e52a
commit 5e5d8c8883
No known key found for this signature in database
2 changed files with 32 additions and 1 deletions

View file

@ -9,7 +9,7 @@ GOLANGCI_LINT := $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lin
LDFLAGS := -s -w
BUILD_FLAGS := -ldflags "$(LDFLAGS)"
.PHONY: all build clean fmt format lint test run help vet tidy
.PHONY: all build clean fmt format lint test run help vet tidy install-hooks
# Default target
all: fmt vet lint build
@ -58,6 +58,13 @@ run: build ## Build and run in stdio mode
run-remote: build ## Build and run in remote mode
./$(BINARY_NAME) -mode=remote
## Git hooks
install-hooks: ## Install git hooks
cp scripts/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
@echo "Git hooks installed successfully"
## Help
help: ## Show this help

24
scripts/hooks/pre-commit Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
# ABOUTME: Pre-commit hook that runs formatting and linting checks.
# ABOUTME: Install with `make install-hooks`.
set -e
echo "Running pre-commit checks..."
# Run go fmt and check if there are any changes
echo "Checking formatting..."
UNFORMATTED=$(gofmt -l .)
if [ -n "$UNFORMATTED" ]; then
echo "Error: The following files are not formatted:"
echo "$UNFORMATTED"
echo ""
echo "Run 'make fmt' to format them."
exit 1
fi
# Run linter
echo "Running linter..."
make lint
echo "Pre-commit checks passed!"