github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/hooks/prepare-commit-msg (about)

     1  #!/bin/bash
     2  
     3  errors=0
     4  for file in $(git diff --cached --name-only | grep "\.go"); do
     5    diff="$(gofmt -d "${file}")"
     6    if [[ -n "$diff" ]]; then
     7      echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1
     8      errors=1
     9    fi
    10  done
    11  
    12  if [[ $errors == "1" ]]; then
    13    echo "# To fix these errors, run gofmt -w <file>." >> $1
    14    echo "# If you want to commit in spite of these format errors," >> $1
    15    echo "# then delete this line. Otherwise, your commit will be" >> $1
    16    echo "# aborted." >> $1
    17  fi