-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
72 lines (64 loc) · 2.77 KB
/
update
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# This is an example for a Git Checkstyle "update" hook
#
# Author: Adrian Mörchen
#
# Inspired by (Thank you all!):
# * Our old SVN Checkstyle Hook for Communote (http://www.communote.com)
# * https://gist.github.com/davetron5000/37350
# * https://gist.github.com/caniszczyk/1327469
# * http://bluec0re.blogspot.de/2012/05/git-pre-receive-hook-with-checkstyle.html
# * http://ncona.com/2013/01/git-hook-to-run-code-static-analysis/
# * and a lot of others and Google and SE search
#
source hooks/checkstyle.cfg
echo " "
echo "Checking your style (Version: 06/26/2013). Please wait..."
echo " "
refname=$1
oldrev=$(git rev-parse $2)
newrev=$(git rev-parse $3)
exit_status=0
mkdir -p $TEMP_BASE_PATH/$newrev
mkdir -p $TEMP_BASE_PATH/results
git diff-tree --no-commit-id -r $oldrev $newrev > $TEMP_BASE_PATH/$newrev/git_diff-tree
while read -r line; do
# Example of line: :000000 100644 0000000000000000000000000000000000000000 af7077beb4e7ef5323e231c3c585a41938a73767 A test.txt
line=$(echo $line | tr ":" " ")
commit_parameters=($line)
if [ "${commit_parameters[4]}" != "D" ]; then
if [ "${commit_parameters[5]: -5}" == ".java" ]; then
# echo "Found file ${commit_parameters[5]} in revision ${commit_parameters[3]}"
temp_file=$TEMP_BASE_PATH/$newrev/${commit_parameters[3]}/${commit_parameters[5]}
mkdir -p $(dirname $temp_file)
git show $newrev:${commit_parameters[5]} > $temp_file
mkdir -p $(dirname $TEMP_BASE_PATH/results/${commit_parameters[5]}_new.log)
$CHECKSTYLE_COMMAND $temp_file | grep -v "Starting audit" | grep -v "Audit done" > $TEMP_BASE_PATH/results/${commit_parameters[5]}_new.log
if [ -f $TEMP_BASE_PATH/results/${commit_parameters[5]}_old.log ]; then
checkstyle_old_count=$(wc -l < $TEMP_BASE_PATH/results/${commit_parameters[5]}_old.log)
else
checkstyle_old_count=$NO_OLD_FILE_ALLOWED_ERRORS
fi
checkstyle_new_count=$(wc -l < $TEMP_BASE_PATH/results/${commit_parameters[5]}_new.log)
if [ $checkstyle_new_count -gt $checkstyle_old_count ]; then
exit_status=1
echo " "
echo "${commit_parameters[5]}: There was/where $checkstyle_new_count checkstyle error(s) (old $checkstyle_old_count), please review and fix them:"
echo " "
sed 's|'$TEMP_BASE_PATH/$newrev'||g' < $TEMP_BASE_PATH/results/${commit_parameters[5]}_new.log
echo " "
else
if [ -f $TEMP_BASE_PATH/results/${commit_parameters[5]}_old.log ]; then
rm $TEMP_BASE_PATH/results/${commit_parameters[5]}_old.log
fi
mv $TEMP_BASE_PATH/results/${commit_parameters[5]}_new.log $TEMP_BASE_PATH/results/${commit_parameters[5]}_old.log
fi
fi
fi
done < $TEMP_BASE_PATH/$newrev/git_diff-tree
rm -r $TEMP_BASE_PATH/$newrev
echo " "
echo "Done. Thanks for your patience."
echo " "
exit $exit_status