forked from Remi-Gau/check_my_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-push.sample
executable file
·52 lines (34 loc) · 1.67 KB
/
pre-push.sample
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
#!/bin/sh
# Things you need to do
# 1. Copy this file into your project/.git/hooks
# 2. rename it to pre-push
# 3. You might need to modify the `alias matlab` line below to point this script to where matlab is
# on your computer.
# 4. Make this file executable with `chmod +x .git/hooks/pre-push`
# 5. Now your code quality will be checked when you push your code to your remote.
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
# If you want to change how strict the rules are.
recursive='1'
cplx_thrs='[15 20]'
comment_thres='[20 10]'
# depending on your matlab install you might need to create an alias for this to work.
alias matlab="/usr/local/MATLAB/R2017a/bin/matlab"
report_file='check_my_code_report.txt'
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
clear
echo "\n\n🚧 🚧 🚧 Checking code quality before pushing. 🚧 🚧 🚧\n\n"
if [ -f "$report_file" ]; then
rm $report_file
fi
matlab -nojvm -nosplash -r "if exist('check_my_code', 'file')==2 ; check_my_code($recursive, $cplx_thrs, $comment_thres, 1); end; exit;"
[ -s "$report_file" ]
if [ "$?" = "0 0" ]; then
echo "\n\n🚧 🚧 🚧 You can't push until your code been properly cleaned. 🚧 🚧 🚧\n\n"
# if you remove this line then it won't block push but send message on command line
exit 1
else
echo "\n\n🎉 🎉 🎉 Your code is good to push. 🎉 🎉 🎉\n\n"
exit 0
fi