github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/hooks/pre-commit (about)

     1  # Copyright (C) 2020, Oracle and/or its affiliates.
     2  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  #!/bin/sh
     4  
     5  # git gofmt pre-commit hook
     6  #
     7  # This script does not handle file names that contain spaces.
     8  gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
     9  [ -z "$gofiles" ] && exit 0
    10  
    11  unformatted=$(gofmt -l $gofiles)
    12  [ -z "$unformatted" ] && exit 0
    13  
    14  # Some files are not gofmt'd. Print message and fail.
    15  
    16  echo >&2 "Go files must be formatted with gofmt. Please run:"
    17  for fn in $unformatted; do
    18  	echo >&2 "  gofmt -w $PWD/$fn"
    19  done
    20  
    21  exit 1
    22