Skip to content

Instantly share code, notes, and snippets.

@jstruzik
Created January 10, 2020 15:31
Show Gist options
  • Save jstruzik/13cd331bcf0b17f20cd120fe0d693130 to your computer and use it in GitHub Desktop.
Save jstruzik/13cd331bcf0b17f20cd120fe0d693130 to your computer and use it in GitHub Desktop.
Git pre-commit hook to check copyright headers for current year
#!/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