mirror of https://github.com/k3s-io/k3s
25 lines
879 B
Bash
Executable File
25 lines
879 B
Bash
Executable File
#!/bin/bash
|
|
|
|
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
|
|
|
errors=0
|
|
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v "third_party"); do
|
|
diff="$(git show ":${file}" | gofmt -s -d)"
|
|
if [[ -n "$diff" ]]; then
|
|
echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1
|
|
errors=1
|
|
fi
|
|
boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})"
|
|
if [[ "$boilerplate" -eq "0" ]]; then
|
|
echo "# *** ERROR: *** File ${file} needs the boilerplate header in hooks/boilerplate.txt." >> $1
|
|
errors=1
|
|
fi
|
|
done
|
|
|
|
if [[ $errors == "1" ]]; then
|
|
echo "# To fix these errors, run gofmt -s -w <file>." >> $1
|
|
echo "# If you want to commit in spite of these format errors," >> $1
|
|
echo "# then delete this line. Otherwise, your commit will be" >> $1
|
|
echo "# aborted." >> $1
|
|
fi
|