@@ -14,46 +14,57 @@ changed_files=$(git diff-index --cached $against | \
14
14
grep -E ' [MA] .*\.(c|cpp|cc|cxx)$' | cut -d' ' -f 2)
15
15
16
16
17
- if [ -n " $changed_files " ]; then
18
- cppcheck --enable=warning,performance,portability --inline-suppr --error-exitcode=1 --platform=win64 --force $changed_files
19
- err=$?
20
- if [ $err -ne 0 ]; then
21
- echo " [rt-thread][cppcheck] we found a obvious fault, please fix the error then commit again"
22
- exit $err
23
- else
24
- echo " [rt-thread][cppcheck] cppcheck ok."
17
+ if which cppcheck > /dev/null; then
18
+ if [ -n " $changed_files " ]; then
19
+ cppcheck --enable=warning,performance,portability --inline-suppr --error-exitcode=1 --platform=win64 --force $changed_files
20
+ err=$?
21
+ if [ $err -ne 0 ]; then
22
+ echo " [rt-thread][cppcheck] we found a obvious fault, please fix the error then commit again"
23
+ exit $err
24
+ else
25
+ echo " [rt-thread][cppcheck] cppcheck ok."
26
+ fi
25
27
fi
28
+ else
29
+ echo " cppcheck does not exist"
26
30
fi
27
31
28
32
# We only filter the file name with c or cpp or h file.
29
33
# astyle only astyle the added file[because of code reivewer], if you want change modify file, please use [MA]
30
34
changed_files=$( git diff-index --cached $against | \
31
35
grep -E ' [MA] .*\.(c|cpp|h)$' | cut -d' ' -f 2)
32
36
33
-
34
- if [ -n " $changed_files " ]; then
35
- astyle --style=allman --indent=spaces=4 --indent=spaces=4 --indent=spaces=4 --pad-header --pad-header --pad-header --align-pointer=name --lineend=linux --convert-tabs --verbose $changed_files
36
- err=$?
37
- if [ $err -ne 0 ]; then
38
- echo " [rt-thread][astyle] we found a obvious fault, please fix the error then commit again"
39
- exit $err
40
- else
41
- echo " [rt-thread][astyle] astyle file ok"
37
+ if which astyle > /dev/null; then
38
+ if [ -n " $changed_files " ]; then
39
+ astyle --style=allman --indent=spaces=4 --indent=spaces=4 --indent=spaces=4 --pad-header --pad-header --pad-header --align-pointer=name --lineend=linux --convert-tabs --verbose $changed_files
40
+ err=$?
41
+ if [ $err -ne 0 ]; then
42
+ echo " [rt-thread][astyle] we found a obvious fault, please fix the error then commit again"
43
+ exit $err
44
+ else
45
+ echo " [rt-thread][astyle] astyle file ok"
46
+ fi
42
47
fi
48
+ else
49
+ echo " astyle does not exist"
43
50
fi
44
51
45
-
46
52
# We only filter the file name with c or cpp file.
47
53
changed_files=$( git diff-index --cached $against | \
48
54
grep -E ' [MA] .*\.(c|cpp|h)$' | cut -d' ' -f 2)
49
55
# formatting check
50
56
# https://github.com/mysterywolf/formatting
51
57
# formatting cmd ref https://github.com/supperthomas/git_auto_script
52
- if [ -n " $changed_files " ]; then
53
- formatting $changed_files
54
- echo " [rt-thread] formatting $changed_files is ok"
55
- git add $changed_files
56
- exit 0
58
+ if which formatting > /dev/null; then
59
+ if [ -n " $changed_files " ]; then
60
+ formatting $changed_files
61
+ echo " [rt-thread] formatting $changed_files is ok"
62
+ git add $changed_files
63
+ exit 0
64
+ fi
65
+ else
66
+ echo " formatting does not exist"
57
67
fi
68
+
58
69
exit 0
59
70
0 commit comments