2014-06-06 23:40:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-06-23 18:34:44 +00:00
|
|
|
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
|
|
|
|
2014-06-24 22:01:08 +00:00
|
|
|
files_need_gofmt=""
|
|
|
|
files_need_boilerplate=""
|
2014-09-04 00:00:30 +00:00
|
|
|
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps"); do
|
2014-06-24 22:01:08 +00:00
|
|
|
# Check for files that fail gofmt.
|
2014-06-13 05:03:00 +00:00
|
|
|
diff="$(git show ":${file}" | gofmt -s -d)"
|
2014-06-06 23:40:48 +00:00
|
|
|
if [[ -n "$diff" ]]; then
|
2014-06-24 22:01:08 +00:00
|
|
|
files_need_gofmt="${files_need_gofmt} ${file}"
|
2014-06-06 23:40:48 +00:00
|
|
|
fi
|
2014-06-24 22:01:08 +00:00
|
|
|
|
|
|
|
# Check for files without the required boilerplate.
|
2014-06-23 18:34:44 +00:00
|
|
|
boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})"
|
2014-06-26 00:11:48 +00:00
|
|
|
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})"
|
2014-06-23 18:34:44 +00:00
|
|
|
if [[ "$boilerplate" -eq "0" ]]; then
|
2014-06-24 22:01:08 +00:00
|
|
|
files_need_boilerplate="${files_need_boilerplate} ${file}"
|
2014-06-23 18:34:44 +00:00
|
|
|
fi
|
2014-06-06 23:40:48 +00:00
|
|
|
done
|
|
|
|
|
2014-06-24 22:01:08 +00:00
|
|
|
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
|
2014-06-06 23:40:48 +00:00
|
|
|
fi
|