Skip to content

Instantly share code, notes, and snippets.

@yosida95
Created April 13, 2018 09:46
Show Gist options
  • Save yosida95/bcefec15e15c12c3bd0ec33e8ae48a9d to your computer and use it in GitHub Desktop.
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
#!/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