-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpre-commit
executable file
·63 lines (55 loc) · 1.05 KB
/
pre-commit
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
main() {
run_gofmt
run_golint
run_govet
run_unit_tests
}
log_error() {
echo "$*" 1>&2
}
log_info() {
echo "$*" 1>&1
}
run_gofmt() {
log_info 'Running format...'
GOFMT_FILES=$(gofmt -l .)
if [ -n "$GOFMT_FILES" ]
then
log_error "gofmt failed for the following files:
$GOFMT_FILES
please run 'gofmt -w .' on your changes before committing."
exit 1
fi
}
run_golint() {
log_info 'Running lint...'
GOLINT_ERRORS=$(golint ./... | grep -v "Id should be")
if [ -n "$GOLINT_ERRORS" ]
then
log_error "golint failed for the following reasons:
$GOLINT_ERRORS
please run 'golint ./...' on your changes before committing."
exit 1
fi
}
run_govet() {
log_info 'Running vet...'
go vet ./...
GOVET_ERRORS=$(go vet ./... 2>&1)
if [ -n "$GOVET_ERRORS" ]
then
log_error "go vet failed for the following reasons:
$GOVET_ERRORS
please run 'go vet ./...' on your changes before committing."
exit 1
fi
}
run_unit_tests() {
if [ -z "$NOTEST" ]
then
log_info 'Running tests...'
go test ./...
fi
}
main