diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50581ddda..869045d40 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,7 @@ repos: - id: detect-private-key exclude: testdata - id: mixed-line-ending +- repo: . + rev: main + hooks: + - id: validate-copyright-year diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 000000000..b8af8e468 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,4 @@ +- id: validate-copyright-year + name: Validate copyright year + entry: hack/check-copyright-year.sh + language: script diff --git a/hack/check-copyright-year.sh b/hack/check-copyright-year.sh new file mode 100644 index 000000000..5d282486c --- /dev/null +++ b/hack/check-copyright-year.sh @@ -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