Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Use .git/hooks/pre-push hook to check for correctly formatted code (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykazakov authored Aug 16, 2017
1 parent 2f40244 commit 9ae6eb7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .gofmt_exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bindata_assetfs\.go
sqlbindata
design/.*
vendor/.*
app/.*
client/.*
tool/cli/.*
6 changes: 6 additions & 0 deletions .pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -x
set -e

make check-go-format
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,31 @@ help:/
} \
}' $(MAKEFILE_LIST)

GOFORMAT_FILES := $(shell find . -name '*.go' | grep -vEf .gofmt_exclude)

.PHONY: check-go-format
## Exists with an error if there are files whose formatting differs from gofmt's
check-go-format: prebuild-check
@gofmt -s -l ${SOURCES} 2>&1 \
@gofmt -s -l ${GOFORMAT_FILES} 2>&1 \
| tee /tmp/gofmt-errors \
| read \
&& echo "ERROR: These files differ from gofmt's style (run 'make format-go-code' to fix this):" \
&& cat /tmp/gofmt-errors \
&& exit 1 \
|| true


.PHONY: install-git-hooks
## Creates useful git hooks (e.g. pre-push go-format-code check)
install-git-hooks:
@ln -sfv ../../.pre-push .git/hooks/pre-push

CLEAN_TARGETS += clean-git-hooks
.PHONY: clean-git-hooks
## Removes hooks that have been installed with the "install-git-hooks" target
clean-git-hooks:
@test "$(shell readlink -f .git/hooks/pre-push)" = "${CUR_DIR}/.pre-push" \
&& rm -v .git/hooks/pre-push \
|| true

.PHONY: release
release: all
Expand All @@ -121,7 +134,7 @@ govet:
.PHONY: format-go-code
## Formats any go file that differs from gofmt's style
format-go-code: prebuild-check
@gofmt -s -l -w ${SOURCES}
@gofmt -s -l -w ${GOFORMAT_FILES}

.PHONY: build
## Build server and client.
Expand Down

0 comments on commit 9ae6eb7

Please sign in to comment.