Created
April 13, 2018 09:46
-
-
Save yosida95/bcefec15e15c12c3bd0ec33e8ae48a9d to your computer and use it in GitHub Desktop.
Check Java format against google-java-format and prevent git commit if found violations
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
#!/usr/bin/env bash | |
google_java_format=$HOME/.local/lib/google-java-format-1.5-all-deps.jar | |
[ -f "$google_java_format" ] || exit 1 | |
git diff --name-only --cached| { | |
code=0 | |
while IFS= read -r file; do | |
[ -f "$file" ] || continue | |
case "$file" in | |
*.java) | |
if ! java -jar "$google_java_format" --set-exit-if-changed --fix-imports-only "$file" >/dev/null 2>&1; then | |
echo $file >&2 | |
code=1 | |
fi | |
;; | |
esac | |
done | |
exit $code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment