The hooks target uses git rev-parse --git-common-dir so it works from both the main checkout and linked worktrees.
49 lines
1.4 KiB
Makefile
49 lines
1.4 KiB
Makefile
# sfdupes is pure Go; disable cgo so builds never touch the host C
|
|
# toolchain.
|
|
export CGO_ENABLED = 0
|
|
|
|
BINARY := sfdupes
|
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
|
LDFLAGS := -X main.Version=$(VERSION)
|
|
|
|
.PHONY: all build test lint fmt fmt-check check docker hooks clean
|
|
|
|
all: check build
|
|
|
|
build:
|
|
go build -ldflags "$(LDFLAGS)" -o $(BINARY)
|
|
|
|
test:
|
|
@go test -timeout 30s -cover ./... || \
|
|
{ echo "--- Rerunning with -v for details ---"; \
|
|
go test -timeout 30s -v ./...; exit 1; }
|
|
|
|
lint:
|
|
golangci-lint run --config .golangci.yml ./...
|
|
|
|
fmt:
|
|
gofmt -s -w .
|
|
|
|
fmt-check:
|
|
@files="$$(gofmt -l -s .)"; if [ -n "$$files" ]; then \
|
|
echo "gofmt: files not formatted:"; echo "$$files"; exit 1; fi
|
|
|
|
check: test lint fmt-check
|
|
|
|
docker:
|
|
docker build -t $(BINARY) .
|
|
|
|
# Hooks are shared between the main checkout and all worktrees, so
|
|
# resolve the common git dir instead of assuming .git is a directory.
|
|
HOOKS_DIR := $(shell git rev-parse --git-common-dir)/hooks
|
|
|
|
hooks:
|
|
@printf '#!/bin/sh\nset -e\n' > $(HOOKS_DIR)/pre-commit
|
|
@printf 'go mod tidy\ngo fmt ./...\n' >> $(HOOKS_DIR)/pre-commit
|
|
@printf 'git diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> $(HOOKS_DIR)/pre-commit
|
|
@printf 'make check\n' >> $(HOOKS_DIR)/pre-commit
|
|
@chmod +x $(HOOKS_DIR)/pre-commit
|
|
|
|
clean:
|
|
rm -f $(BINARY) files.dat
|