Home | History | Annotate | Download | only in annotation-tools
      1 #!/bin/sh
      2 
      3 # This file will be used as .git/hooks/pre-commit .
      4 # However, it should be edited as .git.pre-commit .
      5 # You can install it by running: ant prep
      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 formatted.java.files in
     13 # build.xml. Otherwise `ant 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 '/eclipse/' ` || true
     16 # echo CHANGED_JAVA_FILES "'"${CHANGED_JAVA_FILES}"'"
     17 if [ ! -z "$CHANGED_JAVA_FILES" ]; then
     18     (((cd .run-google-java-format && git pull -q) || git clone -q https://github.com/plume-lib/run-google-java-format.git .run-google-java-format) || true)
     19     ## For debugging:
     20     # echo "CHANGED_JAVA_FILES: ${CHANGED_JAVA_FILES}"
     21     python .run-google-java-format/check-google-java-format.py --aosp ${CHANGED_JAVA_FILES}
     22 fi
     23 
     24 # This is to handle non-.java files, since the above already handled .java files.
     25 # May need to remove files that are allowed to have trailing whitespace.
     26 CHANGED_STYLE_FILES=`git diff --staged --name-only --diff-filter=ACM | grep -v '.png$' | grep -v '.xcf$'` || true
     27 if [ ! -z "$CHANGED_STYLE_FILES" ]; then
     28     # echo "CHANGED_STYLE_FILES: ${CHANGED_STYLE_FILES}"
     29     grep -q '[[:blank:]]$' ${CHANGED_STYLE_FILES} 2>&1 && (echo "Some files have trailing whitespace:" && grep -l '[[:blank:]]$' ${CHANGED_STYLE_FILES} && exit 1)
     30 fi
     31