Copyright year precommit hook
Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
parent
75bc5bdc7e
commit
f1e177fee7
@ -15,3 +15,7 @@ repos:
|
||||
- id: detect-private-key
|
||||
exclude: testdata
|
||||
- id: mixed-line-ending
|
||||
- repo: .
|
||||
rev: main
|
||||
hooks:
|
||||
- id: validate-copyright-year
|
||||
|
4
.pre-commit-hooks.yaml
Normal file
4
.pre-commit-hooks.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
- id: validate-copyright-year
|
||||
name: Validate copyright year
|
||||
entry: hack/check-copyright-year.sh
|
||||
language: script
|
21
hack/check-copyright-year.sh
Normal file
21
hack/check-copyright-year.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user