Copyright year precommit hook

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Margo Crawford 2021-01-05 14:02:28 -08:00 committed by Andrew Keesler
parent 75bc5bdc7e
commit f1e177fee7
3 changed files with 29 additions and 0 deletions

View File

@ -15,3 +15,7 @@ repos:
- id: detect-private-key - id: detect-private-key
exclude: testdata exclude: testdata
- id: mixed-line-ending - id: mixed-line-ending
- repo: .
rev: main
hooks:
- id: validate-copyright-year

4
.pre-commit-hooks.yaml Normal file
View File

@ -0,0 +1,4 @@
- id: validate-copyright-year
name: Validate copyright year
entry: hack/check-copyright-year.sh
language: script

View File

@ -0,0 +1,21 @@
#
# Check if copyright statements include the current year
#
files=git diff --cached --name-only
year=date +"%Y"
for f in $files; do
head -10 $f | grep -i copyright 2>&1 1>/dev/null || continue
if ! grep -i -e "copyright.*$year" $f 2>&1 1>/dev/null; then
missing_copyright_files="$missing_copyright_files $f"
fi
done
if [ -n "$missing_copyright_files" ]; then
echo "$year is missing in the copyright notice of the following files:"
for f in $missing_copyright_files; do
echo " $f"
done
exit 1
fi