-
Notifications
You must be signed in to change notification settings - Fork 520
/
.pre-commit-intel
executable file
·35 lines (29 loc) · 1.23 KB
/
.pre-commit-intel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
#
# A pre-commit hook script to check that an existing Intel copyright line within
# the first 15 lines, contains the current year, which would be the last commit
# date for this file..
#
# Create a symbolic link to this file from .git/hooks/pre-commit to enable it:
# cd acrn-hypervisor/.git/hooks; ln -s ../.pre-commit-intel pre-commit
# Redirect output to stderr.
exec 1>&2
# Don't run this pre-commit if the submitter's email is not from intel.com
EMAIL=$(git config user.email)
[[ ! "$EMAIL" == *"intel.com" ]] && { exit 0; }
RED='\033[0;31m'
NOCOLOR='\033[0m'
found_mismatch=""
commit_year=$(date +%Y)
for filename in $(git diff --cached --name-only --diff-filter=ACM)
do
wrong_year=$(head -15 "$filename" | grep -i ".*Copyright.*Intel" | grep -v "$commit_year")
[ ! -z "$wrong_year" ] && [ -z "$found_mismatch" ] && { found_mismatch="yes"; \
echo -e "\n${RED}ERROR: As an Intel contributor ($EMAIL), " \
"keep the Intel copyright year updated: ${NOCOLOR}\n"; }
[ ! -z "$wrong_year" ] && { echo -e " ${RED}$filename${NOCOLOR}: $wrong_year "\
"${RED}must be updated to contain ${NOCOLOR}$commit_year."; }
done
# if we had a mismatch hit, exit with an error
[ ! -z "$found_mismatch" ] && exit -1;
exit 0;