github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/hooks/pre-commit (about) 1 #!/usr/bin/env bash 2 # This file modified from k8s 3 # https://github.com/kubernetes/kubernetes/blob/master/hooks/pre-commit 4 # Now It's removed, The Reason is https://github.com/kubernetes/community/issues/729 5 # The PR is https://github.com/kubernetes/kubernetes/pull/47673 6 7 # How to use this hook? 8 # ln -s hooks/pre-commit .git/hooks/ 9 # In case hook is not execublock 10 # chmod +x .git/hooks/pre-commit 11 12 readonly reset=$(tput sgr0) 13 readonly red=$(tput bold; tput setaf 1) 14 readonly green=$(tput bold; tput setaf 2) 15 16 readonly goword=./tools/bin/goword 17 18 exit_code=0 19 20 # comment it by default. You can uncomment it. 21 # echo -ne "Checking that it builds..." 22 # if ! OUT=$(make 2>&1); then 23 # echo 24 # echo "${red}${OUT}" 25 # exit_code=1 26 # else 27 # echo "${green}OK" 28 # fi 29 # echo "${reset}" 30 31 echo -ne "Checking for files that need gofmt... " 32 files_need_gofmt=() 33 files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^_vendor")) 34 for file in "${files[@]}"; do 35 # Check for files that fail gofmt. 36 diff="$(git show ":${file}" | gofmt -s -d 2>&1)" 37 if [[ -n "$diff" ]]; then 38 files_need_gofmt+=("${file}") 39 fi 40 done 41 42 if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then 43 echo "${red}ERROR!" 44 echo "Some files have not been gofmt'd. To fix these errors, " 45 echo "copy and paste the following:" 46 echo " gofmt -s -w ${files_need_gofmt[@]}" 47 exit_code=1 48 else 49 echo "${green}OK" 50 fi 51 echo "${reset}" 52 53 echo -ne "Checking for files that need goword... " 54 files_need_goword=() 55 files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^_vendor")) 56 for file in "${files[@]}"; do 57 # Check for files that fail goword. 58 diff=$(${goword} ${file}) 59 if [[ -n "$diff" ]]; then 60 files_need_goword+=("${file}") 61 fi 62 done 63 64 if [[ "${#files_need_goword[@]}" -ne 0 ]]; then 65 echo "${red}ERROR!" 66 echo "Some files may have spelling errors." 67 echo "copy and paste the following for where fails this test:" 68 echo " $ ${goword} ${files_need_goword[@]}" 69 exit_code=1 70 else 71 echo "${green}OK" 72 fi 73 echo "${reset}" 74 75 if [[ "${exit_code}" != 0 ]]; then 76 echo "${red}Aborting commit${reset}" 77 fi 78 exit ${exit_code}