Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (24 sloc) 593 Bytes
#!/bin/sh
# get go files added to this commit.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$')
[ -z "$gofiles" ] && exit 0
# check cyclomatic index (just to show)
# gocyclo (https://github.com/fzipp/gocyclo) needs to be installed.
for fn in $gofiles; do
gocyclo -top 5 $fn
done
# run goimport
unimported=$(goimports -l $gofiles)
for fn in $unimported; do
goimports -w $fn
echo >&2 "goimports -w $fn"
git add $fn
done
unformatted=$(gofmt -l $gofiles)
# run gofmt
for fn in $unformatted; do
gofmt -s -w $fn
echo >&2 "gofmt -s -w $fn"
git add $fn
done
exit 0