1#!/bin/sh 2# 3# Copy to .git/hooks and make executable. 4# 5# Copyright (c) 2011, 2013 Erik Johansson <erijo@licq.org> 6# Copyright (c) 2011 Anders Olofsson <flynd@licq.org> 7# Distributed under the terms of the GNU GPL version 2. 8# 9 10year=$(date +%Y) 11exit_status=0 12 13error() 14{ 15 echo "Error: $*" >& 2 16 exit_status=1 17} 18 19verify_copyright_year() 20{ 21 file="$1" 22 sha1="$2" 23 if ! git cat-file -p $sha1 | grep -q "Copyright"; then 24 if echo "$file" | grep -Eq '\.(c|cpp|h)$'; then 25 error "no copyright line in '$file'" 26 fi 27 return 28 fi 29 30 if ! git cat-file -p $sha1 | grep -Eq "Copyright.*$year"; then 31 if echo "$file" | grep -Eq '\.pot$'; then 32 return 33 fi 34 error "copyright line in '$file' does not include current year" 35 fi 36} 37 38 39# Loop on lines, not words 40IFS=" 41" 42 43for file in $(git diff-index --cached --full-index --diff-filter=AM HEAD); do 44 sha1_staged=$(echo $file | cut -d' ' -f4) 45 filename=$(echo $file | cut -d' ' -f2) 46 47 if echo "$filename" | grep -q "3rdparty/"; then 48 continue 49 fi 50 51 verify_copyright_year "$filename" "$sha1_staged" 52done 53unset IFS 54 55exit $exit_status 56