Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gofmt #64

Merged
merged 7 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
validate_config: 1
tasks:
ubuntu1804:
shell_commands:
- "echo +++ Check go format"
- "./check-gofmt.sh `find go -name '*.go'`"
build_targets:
- "//..."
test_targets:
Expand Down
11 changes: 11 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh


########################################################################
# Check that all Go files have been gofmt'd.
########################################################################
# Find all change go files.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
[ -z "$gofiles" ] && exit 0

source ./check-gofmt.sh "$gofiles"
15 changes: 15 additions & 0 deletions check-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Source: https://golang.org/misc/git/pre-commit

unformatted=$(gofmt -l "$@")
[ -z "$unformatted" ] && exit 0

# Some files are not gofmt'd. Print message and fail.

echo >&2 "Go files must be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo >&2 " gofmt -w $PWD/$fn"
done

exit 1
8 changes: 8 additions & 0 deletions setup-githooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Copies git hooks from .githooks/ to .git/hooks/, overriding any hooks you may
# have previously had there.
cp .githooks/* .git/hooks/
for h in `ls .githooks/* | xargs basename`; do
chmod ug+x .git/hooks/$h
done