Skip to content

Commit a9b6c2e

Browse files
committed
build: use lefthook for git hooks
1 parent d31490d commit a9b6c2e

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

Makefile

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ BIN := $(notdir $(CURDIR))
22

33
all:
44
@if [ ! -f ".git/hooks/pre-commit" ]; then \
5-
$(MAKE) precommit-install; \
5+
$(MAKE) install-hooks; \
66
fi
77
$(MAKE) build
88
$(MAKE) run
@@ -31,28 +31,6 @@ uninstall:
3131
lint:
3232
golangci-lint run ./...
3333

34-
.PHONY: precommit-install
35-
precommit-install:
36-
@echo "Installing pre-commit hooks..."
37-
@echo "#!/bin/sh\n\nmake precommit" > .git/hooks/pre-commit
38-
@chmod +x .git/hooks/pre-commit
39-
@echo "Pre-commit hooks installed."
40-
41-
.PHONY: precommit
42-
precommit:
43-
@STAGED_FILES=$$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.go$$'); \
44-
if [ -z "$$STAGED_FILES" ]; then \
45-
echo "No staged Go files to check."; \
46-
else \
47-
set -e; \
48-
echo "Running pre-commit checks..."; \
49-
echo "go fmt"; \
50-
go fmt ./...; \
51-
git add $$STAGED_FILES; \
52-
echo "go vet"; \
53-
go vet ./...; \
54-
echo "golangci-lint"; \
55-
golangci-lint run ./...; \
56-
echo "go test"; \
57-
go test -v ./...; \
58-
fi
34+
.PHONY: install-hooks
35+
install-hooks:
36+
lefthook install

lefthook.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pre-commit:
2+
parallel: true
3+
commands:
4+
fmt:
5+
glob: "*.go"
6+
run: go fmt ./...
7+
stage_fixed: true
8+
vet:
9+
glob: "*.go"
10+
run: go vet ./...
11+
lint:
12+
glob: "*.go"
13+
run: golangci-lint run ./...
14+
test:
15+
glob: "*.go"
16+
run: go test -v ./...

0 commit comments

Comments
 (0)