Skip to content

Instantly share code, notes, and snippets.

@collinpeters
Last active April 19, 2018 18:59
Show Gist options
  • Save collinpeters/9d6418687b7a390d1a20bebc859814be to your computer and use it in GitHub Desktop.
Save collinpeters/9d6418687b7a390d1a20bebc859814be to your computer and use it in GitHub Desktop.
Git commit hook to slap hand if a license header was forgottten
#!/bin/sh
#
# Git commit hook to run a license check on new files in the index. Failed CI builds no more!!
#
# Usage: drop it into <repo>/.git/hooks
# One liner (run from .git/hooks folder): curl -s -O -J https://gist.githubusercontent.com/collinpeters/9d6418687b7a390d1a20bebc859814be/raw/prepare-commit-msg
# Since the check is slow, we only want to run it when new files have been added to the index
NEW_FILES=$(git diff --name-only --diff-filter=A --cached)
if [ ! -z "$NEW_FILES" ]
then
echo "New files are detected. Running mvn license check..."
OUTPUT=$(mvn com.mycila:license-maven-plugin:check | grep "Missing header")
if [ ! -z "$OUTPUT" ]
then
echo "Aborting commit due to missing headers"
echo "$OUTPUT"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment