Skip to content

Commit

Permalink
Update gofmt git hook
Browse files Browse the repository at this point in the history
  • Loading branch information
edsrzf committed Apr 1, 2012
1 parent cc70d30 commit 7c190c4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions .git_hooks/pre-commit/gofmt
Expand Up @@ -6,17 +6,30 @@ test_fmt() {
'
for file in $(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
do
if test "$(git cat-file -p :$file | gofmt -l)" = "<standard input>"
output=$(git cat-file -p :$file | gofmt -l 2>&1)
if test $? -ne 0
then
output=$(echo "$output" | sed "s,<standard input>,$file,")
syntaxerrors="${list}${output}\n"
elif test -n "$output"
then
list="${list}${file}\n"
fi
done
exitcode=0
if test -n "$syntaxerrors"
then
echo >&2 "gofmt found syntax errors:"
printf "$syntaxerrors"
exitcode=1
fi
if test -n "$list"
then
echo >&2 "gofmt needs to format these files (run gofmt -w):"
printf "$list"
exit 1
exitcode=1
fi
exit $exitcode
}

case "$1" in
Expand Down

0 comments on commit 7c190c4

Please sign in to comment.