Last active
January 28, 2016 18:17
-
-
Save wyattjoh/d0e561577299ded51c2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright 2012 The Go Authors, 2015 Wyatt Johnson. 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. | |
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep -v 'vendor/' | grep '.go$') | |
unformatted=$(gofmt -l $gofiles) | |
if [ ! -z "$unformatted" ] | |
then | |
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 | |
fi | |
THRESHOLD_WARN=5 | |
THRESHOLD_FAIL=10 | |
LINTWARNINGS=$(golint ./... | grep -v 'vendor/') | |
LINTLINES=$(echo "$LINTWARNINGS" | wc -l | tr -d " ") | |
if [ ! -z "$LINTLINES" ] | |
then | |
echo "$LINTWARNINGS" | |
if [ "$LINTLINES" -ge "${THRESHOLD_FAIL}" ];then | |
echo >&2 "\nTime to tidy up: $LINTLINES lint warnings." | |
exit 1 | |
elif [ "$LINTLINES" -ge "${THRESHOLD_WARN}" ]; then | |
echo >&2 "\nYou should be tidying soon: $LINTLINES lint warnings." | |
elif [ "$LINTLINES" -gt 0 ]; then | |
echo >&2 "\nYou are fairly tidy: $LINTLINES lint warnings." | |
fi | |
fi | |
doclines=$(python scripts/docs.py -l 2>&1 | wc -l | tr -d " ") | |
if [ "$doclines" -gt 0 ] | |
then | |
echo >&2 "Time to regenerate documentation. $doclines README's need updating, run:" | |
echo >&2 " python scripts/docs.py" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment