github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/.githooks/pre-commit (about)

     1  #!/bin/bash
     2  
     3  IFS=$'\n'
     4  year=$(date +'%Y')
     5  
     6  files_without_header=()
     7  required_extensions=(go yaml)
     8  
     9  updated_files=$(git diff --name-only --cached)
    10  if [ -n "$updated_files" ]
    11  then
    12      
    13      for updated_file in $updated_files; do
    14        for extension in $required_extensions; do
    15          if [[ "$updated_file" == *.${extension} ]]; then
    16            files_without_header+=($(grep -L "Copyright ©.*$year" $updated_file))
    17          fi
    18        done
    19      done
    20  
    21      if [ -n "$files_without_header" ]
    22      then
    23          echo "Copyright © $year license header not found in the following newly added files:"
    24          for file in "${files_without_header[@]}"
    25          do
    26              :
    27              echo "   - $file";
    28          done
    29          exit 1;
    30      else
    31          exit 0;
    32      fi
    33  fi