From 037f6b606e7bfc95a0bb933ad54602df702066e7 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 16 Jul 2020 17:52:59 -0400 Subject: [PATCH] Replace lefthook with shell script --- Makefile | 15 +++++++-------- git/pre-commit | 32 ++++++++++++++++++++++++++++++++ git/pre-push | 4 ++++ lefthook.yml | 17 ----------------- 4 files changed, 43 insertions(+), 25 deletions(-) create mode 100755 git/pre-commit create mode 100755 git/pre-push delete mode 100644 lefthook.yml diff --git a/Makefile b/Makefile index 6578183e..c5a821ac 100644 --- a/Makefile +++ b/Makefile @@ -48,16 +48,20 @@ setup: @(cd ./ui && npm ci) .PHONY: setup -setup-dev: setup +setup-dev: setup setup-git @which wire || (echo "Installing Wire" && GO111MODULE=off go get -u github.com/google/wire/cmd/wire) @which ginkgo || (echo "Installing Ginkgo" && GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo) @which goose || (echo "Installing Goose" && GO111MODULE=off go get -u github.com/pressly/goose/cmd/goose) @which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex) @which golangci-lint || (echo "Installing GolangCI-Lint" && cd .. && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0) - @which lefthook || (echo "Installing Lefthook" && GO111MODULE=off go get -u github.com/Arkweid/lefthook) - @lefthook install + @which goimports || (echo "Installing goimports" && GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports) .PHONY: setup-dev +setup-git: + @mkdir -p .git/hooks + (cd .git/hooks && ln -sf ../../git/* .) +.PHONY: setup-git + Jamstash-master: wget -N https://github.com/tsquillario/Jamstash/archive/master.zip unzip -o master.zip @@ -68,11 +72,6 @@ Jamstash-master: check_env: check_go_env check_node_env .PHONY: check_env -check_hooks: - @lefthook add pre-commit - @lefthook add pre-push -.PHONY: check_hooks - check_go_env: @(hash go) || (echo "\nERROR: GO environment not setup properly!\n"; exit 1) @go version | grep -q $(GO_VERSION) || (echo "\nERROR: Please upgrade your GO version\nThis project requires version $(GO_VERSION)"; exit 1) diff --git a/git/pre-commit b/git/pre-commit new file mode 100755 index 00000000..ef07e99c --- /dev/null +++ b/git/pre-commit @@ -0,0 +1,32 @@ +#!/bin/sh +# Copyright 2012 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# git gofmt pre-commit hook +# +# To use, store as .git/hooks/pre-commit inside your repository and make sure +# it has execute permissions. +# +# This script does not handle file names that contain spaces. + +if which goimports > /dev/null; then + gofmtcmd=goimports +else + gofmtcmd=gofmt +fi + +gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') +[ -z "$gofiles" ] && exit 0 + +unformatted=$($gofmtcmd -l $gofiles) +[ -z "$unformatted" ] && exit 0 + +# Some files are not gofmt'd. Print message and fail. + +echo >&2 "Go files must be formatted with '$gofmtcmd'. Please run:" +for fn in $unformatted; do + echo >&2 " $gofmtcmd -w $PWD/$fn" +done + +exit 1 diff --git a/git/pre-push b/git/pre-push new file mode 100755 index 00000000..aa43f4b0 --- /dev/null +++ b/git/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh + +golangci-lint run +make test \ No newline at end of file diff --git a/lefthook.yml b/lefthook.yml deleted file mode 100644 index efce9728..00000000 --- a/lefthook.yml +++ /dev/null @@ -1,17 +0,0 @@ -pre-push: - parallel: true - commands: - unit-tests: - tags: tests - run: go test ./... - lint: - tags: tests - run: golangci-lint run - -pre-commit: - parallel: false - commands: - gofmt: - tags: style - glob: "*.go" - run: gofmt -w {staged_files}; git add {staged_files}