From f11ba4a1b57309cf7c75470df40ea7ab4865e12b Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 12 May 2015 21:59:44 -0700 Subject: [PATCH] Switch git hooks to use pre-commit --- docs/devel/development.md | 3 +- hooks/commit-msg | 10 --- hooks/{prepare-commit-msg => pre-commit} | 82 +++++++++++------------- 3 files changed, 39 insertions(+), 56 deletions(-) delete mode 100755 hooks/commit-msg rename hooks/{prepare-commit-msg => pre-commit} (54%) diff --git a/docs/devel/development.md b/docs/devel/development.md index 556f7c2259a..6d6bdb86118 100644 --- a/docs/devel/development.md +++ b/docs/devel/development.md @@ -105,8 +105,7 @@ directory. This will keep you from accidentally committing non-gofmt'd go code. ``` cd kubernetes/.git/hooks/ -ln -s ../../hooks/prepare-commit-msg . -ln -s ../../hooks/commit-msg . +ln -s ../../hooks/pre-commit . ``` ## Unit tests diff --git a/hooks/commit-msg b/hooks/commit-msg deleted file mode 100755 index d9fa585966f..00000000000 --- a/hooks/commit-msg +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -if [[ "$(grep -c "COMMIT_BLOCKED" $1)" -gt 0 ]]; then - echo "FAILED: Unresolved errors - aborting the commit." - echo "The message of your attempted commit was:" - cat $1 - exit 1 -fi - -exit 0 diff --git a/hooks/prepare-commit-msg b/hooks/pre-commit similarity index 54% rename from hooks/prepare-commit-msg rename to hooks/pre-commit index bfb6a07b77b..486a02808b6 100755 --- a/hooks/prepare-commit-msg +++ b/hooks/pre-commit @@ -6,6 +6,7 @@ files_need_gofmt=() files_need_boilerplate=() files_need_description=() +echo -ne "Checking for files that need gofmt..." files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "third_party" -e "Godeps")) for file in "${files[@]}"; do # Check for files that fail gofmt. @@ -14,7 +15,9 @@ for file in "${files[@]}"; do files_need_gofmt+=("${file}") fi done +echo "done" +echo -ne "Checking for files that need boilerplate..." boiler="${KUBE_HOOKS_DIR}/boilerplate.py" # Check for go files without the required boilerplate. if [[ ${#files[@]} -gt 0 ]]; then @@ -32,7 +35,9 @@ files=($(git diff --cached --name-only --diff-filter ACM | grep "\.py" | grep -v if [[ ${#files} -gt 0 ]]; then files_need_boilerplate+=($("${boiler}" "py" "${files[@]}")) fi +echo "done" +echo -ne "Checking for API descriptions..." # Check API schema definitions for field descriptions for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do # Check for files with fields without description tags @@ -41,59 +46,48 @@ for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v files_need_description+=("${file}") fi done +echo "done" +ret=0 if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then - ( - echo - echo "# *** ERROR: *** Some files have not been gofmt'd. To fix these" - echo "# errors, run gofmt -s -w , 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 + echo + echo "# *** ERROR: *** Some files have not been gofmt'd. To fix these" + echo "# errors, run gofmt -s -w , or cut and paste the following:" + echo "# gofmt -s -w ${files_need_gofmt[@]}" + echo + ret=1 fi if [[ "${#files_need_boilerplate[@]}" -ne 0 ]]; 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 + 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 + ret=1 fi if [[ "${#files_need_description[@]}" -ne 0 ]]; then - ( - echo - echo "# *** ERROR: *** Some API files are missing the required field descriptions" - echo "# Add description tags to all non-inline fields in the following files:" - for file in "${files_need_description[@]}"; do - echo "# ${file}" - done - echo "#" - echo "# Your commit will be aborted unless you fix these." - echo "# COMMIT_BLOCKED_ON_DESCRIPTION" - echo - ) >> $1 + echo + echo "# *** ERROR: *** Some API files are missing the required field descriptions" + echo "# Add description tags to all non-inline fields in the following files:" + for file in "${files_need_description[@]}"; do + echo "# ${file}" + done + echo + ret=1 fi +echo -ne "Checking for docs that need updating..." if ! hack/verify-gendocs.sh > /dev/null; then - ( - echo - echo "# *** ERROR: *** docs are out of sync between cli and markdown" - echo "# run hack/run-gendocs.sh > docs/kubectl.md to regenerate" - echo - echo "#" - echo "# Your commit will be aborted unless you regenerate docs." - echo " COMMIT_BLOCKED_ON_GENDOCS" - echo - ) >> $1 + echo + echo "# *** ERROR: *** docs are out of sync between cli and markdown" + echo "# run hack/run-gendocs.sh > docs/kubectl.md to regenerate" + echo + ret=1 fi +echo "done" + +exit $ret