forked from gbif/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·42 lines (31 loc) · 1.05 KB
/
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
echo '[git hook] executing spotless apply before commit'
# store all staged files
files=$(git diff --name-only --staged)
# get project basedir
BASEDIR=$(git rev-parse --show-toplevel)
# concatenate staged files
for i in $files
do
STAGED_FILES=$STAGED_FILES$BASEDIR/$i,
STAGED_FILES_SPACE_SEPARATED="$STAGED_FILES_SPACE_SEPARATED $i"
done
echo "Files space separated: $STAGED_FILES_SPACE_SEPARATED"
echo "Files comma separated: $STAGED_FILES"
# run spotless only for staged files
mvn spotless:apply "-DspotlessFiles=$STAGED_FILES" --quiet
# add updates after spotless
git add --update $STAGED_FILES_SPACE_SEPARATED
# run spotless check maven
mvn spotless:check "-DspotlessFiles=$STAGED_FILES" --quiet
# store the last exit code in a variable
RESULT=$?
# run one more time if failed
if [ "$RESULT" -ne "0" ]; then
mvn spotless:apply "-DspotlessFiles=$STAGED_FILES" --quiet
git add --update $STAGED_FILES_SPACE_SEPARATED
mvn spotless:check "-DspotlessFiles=$STAGED_FILES" --quiet
RESULT=$?
fi
# return the 'mvn spotless:check' exit code
exit $RESULT