forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-commit-msg
executable file
·56 lines (50 loc) · 1.88 KB
/
prepare-commit-msg
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
#!/bin/bash
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
files_need_gofmt=""
files_need_boilerplate=""
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps"); do
# Check for files that fail gofmt.
diff="$(git show ":${file}" | gofmt -s -d)"
if [[ -n "$diff" ]]; then
files_need_gofmt="${files_need_gofmt} ${file}"
fi
# Check for files without the required boilerplate.
boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})"
if [[ "$boilerplate" -eq "0" ]]; then
files_need_boilerplate="${files_need_boilerplate} ${file}"
fi
done
# Check sh files for boilerplate
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.sh" | grep -v "third_party"); do
# Check for files without the required boilerplate.
boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})"
if [[ "$boilerplate" -eq "0" ]]; then
files_need_boilerplate="${files_need_boilerplate} ${file}"
fi
done
if [[ -n "${files_need_gofmt}" ]]; then
(
echo
echo "# *** ERROR: *** Some files have not been gofmt'd. To fix these"
echo "# errors, run gofmt -s -w <file>, or cut and paste the following:"
echo "# gofmt -s -w ${files_need_gofmt}"
echo "#"
echo "# Your commit will be aborted unless you override this warning. To"
echo "# commit in spite of these format errors, delete the following line:"
echo "# COMMIT_BLOCKED_ON_GOFMT"
) >> $1
fi
if [[ -n "${files_need_boilerplate}" ]]; then
(
echo
echo "# *** ERROR: *** Some files are missing the required boilerplate"
echo "# header from hooks/boilerplate.txt:"
for file in ${files_need_boilerplate}; do
echo "# ${file}"
done
echo "#"
echo "# Your commit will be aborted unless you fix these."
echo "# COMMIT_BLOCKED_ON_BOILERPLATE"
echo
) >> $1
fi