Created
January 10, 2020 15:31
-
-
Save jstruzik/13cd331bcf0b17f20cd120fe0d693130 to your computer and use it in GitHub Desktop.
Git pre-commit hook to check copyright headers for current year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
readonly FILES=$(git diff --diff-filter=ACMRTUXB --cached --name-only) | |
readonly CURRENT_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.*$CURRENT_YEAR" $f 2>&1 1>/dev/null; then | |
INVALID_FILES="$INVALID_FILES $f" | |
fi | |
done | |
if [ -n "$INVALID_FILES" ]; then | |
echo "The following files have an invalid copyright year specified:" | |
for f in $INVALID_FILES; do | |
echo " $f" | |
done | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment