-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre-commit
More file actions
80 lines (65 loc) · 1.98 KB
/
pre-commit
File metadata and controls
80 lines (65 loc) · 1.98 KB
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
73
74
75
76
77
78
79
80
#!/bin/sh
#set TXIncremental=true to use a file list instead of looking the hole repository
TXIncrmental="true"
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*|MINGW*|MSYS*) machine=Windows;;
*) machine="UNKNOWN:${unameOut}"
esac
echo "INFO: Found: " ${machine} "Machine"
rootDir=$(git rev-parse --show-toplevel)
echo "INFO: current Working Directory $rootDir"
pmdRules="$rootDir/.git/hooks/TXCustomRules.xml"
echo "INFO: Found Rules File $pmdRules"
if [ ! -z $TXIncrmental ];
then
# Get staged only files, and create temporary file with the complete list
git diff --name-only --cached | grep -i '.java' > GitStagedFiles
if [ -f ./GitStagedFiles ];
then
filesGitStaged="true"
echo "INFO: files in stage to process"
cat ./GitStagedFiles
else
echo "ERROR: could not create staged files list."
fi
fi
echo "***********************"
echo "INFO: Start analysis..."
if [ $machine == "Windows" ];
then
if [ -z $filesGitStaged ];
then
pmd.bat -d $rootDir -f text -R "$pmdRules"
else
pmd.bat -filelist ./GitStagedFiles -f text -R "$pmdRules"
fi
else
pmd="run.sh pmd"
if [ -z $filesGitStaged ];
then
$pmd -d $rootDir -f text -R "$pmdRules"
else
$pmd -filelist ./GitStagedFiles -f text -R "$pmdRules"
fi
fi
pmdStatus=$?
echo "********** END *************"
if [ -f ./GitStagedFiles ];
then
echo "INFO: removing temporary files..."
rm -f GitStagedFiles
if [ $? -ne 0 ];
then
echo "WARNING: Could not delete ./GitStagedFiles temporary file, you should consider removing it manually"
fi
fi
if [ $pmdStatus -ne 0 ]; then
echo "ERROR: TX Best Practices Offended in the current Commit, FIX code and retry"
# Redirect stdout to stderr
# in order to force complete the commit operation return a 0 status
exec 1>&2
exit 0
fi