| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# This file will be used as ../../.git/hooks/pre-commit. |
| 4 |
# However, it should be edited as checker/bin-devel/git.pre-commit. |
| 5 |
# You can install it by running: (cd .. && ./gradlew installGitHooks) |
| 6 |
|
| 7 |
# Fail if any command fails |
| 8 |
set -e |
| 9 |
|
| 10 |
# "ant -e check-style" would check every file; on commit we only need to |
| 11 |
# check files that changed. |
| 12 |
# Need to keep checked files in sync with getJavaFilesToFormat in build.gradle. |
| 13 |
# Otherwise `./gradlew reformat` might not reformat a file that this |
| 14 |
# hook complains about. |
| 15 |
CHANGED_JAVA_FILES=`git diff --staged --name-only --diff-filter=ACM | grep '\.java$' | grep -v '/jdk/' | grep -v 'stubparser/' | grep -v '/nullness-javac-errors/' ` || true |
| 16 |
# echo CHANGED_JAVA_FILES "'"${CHANGED_JAVA_FILES}"'" |
| 17 |
if [ ! -z "$CHANGED_JAVA_FILES" ]; then |
| 18 |
./gradlew getCodeFormatScripts -q |
| 19 |
## For debugging: |
| 20 |
# echo "CHANGED_JAVA_FILES: ${CHANGED_JAVA_FILES}" |
| 21 |
python checker/bin-devel/.run-google-java-format/check-google-java-format.py --aosp ${CHANGED_JAVA_FILES} || (echo "Try running: ./gradlew reformat" && /bin/false) |
| 22 |
|
| 23 |
BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 24 |
if [ "$BRANCH" = "master" ]; then |
| 25 |
git diff --staged > /tmp/diff.txt |
| 26 |
./gradlew getPlumeScripts -q |
| 27 |
(./gradlew requireJavadocPrivate > /tmp/warnings-rjp.txt 2>&1) || true |
| 28 |
checker/bin-devel/.plume-scripts/lint-diff.py --guess-strip /tmp/diff.txt /tmp/warnings-rjp.txt |
| 29 |
(./gradlew javadocDoclintAll > /tmp/warnings-jda.txt 2>&1) || true |
| 30 |
checker/bin-devel/.plume-scripts/lint-diff.py --guess-strip /tmp/diff.txt /tmp/warnings-jda.txt |
| 31 |
fi |
| 32 |
fi |
| 33 |
|
| 34 |
# This is to handle non-.java files, since the above already handled .java files. |
| 35 |
# May need to remove files that are allowed to have trailing whitespace or are |
| 36 |
# not text files. |
| 37 |
CHANGED_FILES=`git diff --staged --name-only --diff-filter=ACM | grep -v '\.class$' | grep -v '\.gz$' | grep -v '\.jar$' | grep -v '\.pdf$' | grep -v '\.png$' | grep -v '\.xcf$'` || true |
| 38 |
if [ ! -z "$CHANGED_FILES" ]; then |
| 39 |
# echo "CHANGED_FILES: ${CHANGED_FILES}" |
| 40 |
FILES_WITH_TRAILING_SPACES=`grep -l -s '[[:blank:]]$' ${CHANGED_FILES} 2>&1` || true |
| 41 |
if [ ! -z "$FILES_WITH_TRAILING_SPACES" ]; then |
| 42 |
echo "Some files have trailing whitespace: ${FILES_WITH_TRAILING_SPACES}" && exit 1 |
| 43 |
fi |
| 44 |
fi |