-
Notifications
You must be signed in to change notification settings - Fork 34
/
.git.pre-commit
executable file
·42 lines (36 loc) · 1.9 KB
/
.git.pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
# This file will be used as .git/hooks/pre-commit .
# However, it should be edited as .git.pre-commit .
# You can install it by running: ./gradlew installGitHooks
# Fail if any command fails
set -e
# Could instead do "spotlessApply", but then the changes don't appear in this commit.
(cd annotation-file-utilities/ && ./gradlew spotlessCheck -q)
CHANGED_JAVA_FILES=$(git diff --staged --name-only --diff-filter=ACM | grep '\.java$' ) || true
## TODO: the below is written for the Checker Framework and needs to be rewritten to work for AFU.
# echo "CHANGED_JAVA_FILES=${CHANGED_JAVA_FILES}"
# if [ -n "$CHANGED_JAVA_FILES" ]; then
#
# BRANCH=$(git rev-parse --abbrev-ref HEAD)
# if [ "$BRANCH" = "master" ]; then
# git diff --staged > /tmp/diff.txt
# ./gradlew getPlumeScripts -q
# (./gradlew requireJavadoc > /tmp/warnings-rjp.txt 2>&1) || true
# checker/bin-devel/.plume-scripts/lint-diff.py --guess-strip /tmp/diff.txt /tmp/warnings-rjp.txt
# (./gradlew javadocDoclintAll > /tmp/warnings-jda.txt 2>&1) || true
# checker/bin-devel/.plume-scripts/lint-diff.py --guess-strip /tmp/diff.txt /tmp/warnings-jda.txt
# fi
# fi
# This is to handle non-.java files, since the above already handled .java files.
# May need to remove files that are allowed to have trailing whitespace or are
# not text files.
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$' | grep -v 'gradlew') || true
if [ -n "$CHANGED_FILES" ]; then
## For debugging:
# echo "CHANGED_FILES: ${CHANGED_FILES}"
# shellcheck disable=SC2086
FILES_WITH_TRAILING_SPACES=$(grep -l -s '[[:blank:]]$' ${CHANGED_FILES} 2>&1) || true
if [ -n "$FILES_WITH_TRAILING_SPACES" ]; then
echo "Some files have trailing whitespace: ${FILES_WITH_TRAILING_SPACES}" && exit 1
fi
fi