Last active
April 19, 2018 18:59
-
-
Save collinpeters/9d6418687b7a390d1a20bebc859814be to your computer and use it in GitHub Desktop.
Git commit hook to slap hand if a license header was forgottten
This file contains 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 | |
# | |
# 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