-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfmt-check
executable file
·42 lines (40 loc) · 961 Bytes
/
fmt-check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
test_fmt() {
hash gofmt 2>&- || { echo >&2 "gofmt not in PATH."; exit 1; }
IFS='
'
for file in `git diff --cached --name-only --diff-filter=ACM | grep '\.go$'`
do
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 and git add):"
printf "$list"
exitcode=1
fi
exit $exitcode
}
case "$1" in
--about )
echo "Check Go code formatting"
;;
* )
test_fmt
;;
esac