diff --git a/hooks/boilerplate.sh b/hooks/boilerplate.sh new file mode 100755 index 00000000000..33c31cbf5b9 --- /dev/null +++ b/hooks/boilerplate.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Print 1 if the file in $1 has the correct boilerplate header, 0 otherwise. +FILE=$1 +LINES=$(cat "$(dirname $0)/boilerplate.txt" | wc -l) +DIFFER=$(head -$LINES "${FILE}" | diff -q - "$(dirname $0)/boilerplate.txt") + +if [[ -z "${DIFFER}" ]]; then + echo "1" + exit 0 +fi + +echo "0" diff --git a/hooks/boilerplate.txt b/hooks/boilerplate.txt new file mode 100644 index 00000000000..5fd3c3f8157 --- /dev/null +++ b/hooks/boilerplate.txt @@ -0,0 +1,16 @@ +/* +Copyright 2014 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + diff --git a/hooks/prepare-commit-msg b/hooks/prepare-commit-msg index b6f43d3135a..8fdd02b0243 100755 --- a/hooks/prepare-commit-msg +++ b/hooks/prepare-commit-msg @@ -1,5 +1,7 @@ #!/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)" @@ -7,6 +9,11 @@ for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | gr 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