summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsupperthomas <[email protected]>2023-04-23 22:23:31 +0800
committerguo <[email protected]>2023-05-10 19:43:05 +0800
commit4f8d45375bfa64c749813f6c093c16a219e79b90 (patch)
treedf6e9fbb97bc2dfd86dd5eb81e299c4fa752a75e
parent8de0bef8a50030e0242589ec8b2fc5e403a95af6 (diff)
add cmd check
-rw-r--r--.hooks/pre-commit57
1 files changed, 34 insertions, 23 deletions
diff --git a/.hooks/pre-commit b/.hooks/pre-commit
index 71da51b3cd..bcb0d8565f 100644
--- a/.hooks/pre-commit
+++ b/.hooks/pre-commit
@@ -14,15 +14,19 @@ changed_files=$(git diff-index --cached $against | \
grep -E '[MA] .*\.(c|cpp|cc|cxx)$' | cut -d' ' -f 2)
-if [ -n "$changed_files" ]; then
- cppcheck --enable=warning,performance,portability --inline-suppr --error-exitcode=1 --platform=win64 --force $changed_files
- err=$?
- if [ $err -ne 0 ]; then
- echo "[rt-thread][cppcheck] we found a obvious fault, please fix the error then commit again"
- exit $err
- else
- echo "[rt-thread][cppcheck] cppcheck ok."
+if which cppcheck > /dev/null; then
+ if [ -n "$changed_files" ]; then
+ cppcheck --enable=warning,performance,portability --inline-suppr --error-exitcode=1 --platform=win64 --force $changed_files
+ err=$?
+ if [ $err -ne 0 ]; then
+ echo "[rt-thread][cppcheck] we found a obvious fault, please fix the error then commit again"
+ exit $err
+ else
+ echo "[rt-thread][cppcheck] cppcheck ok."
+ fi
fi
+else
+ echo "cppcheck does not exist"
fi
# We only filter the file name with c or cpp or h file.
@@ -30,30 +34,37 @@ fi
changed_files=$(git diff-index --cached $against | \
grep -E '[MA] .*\.(c|cpp|h)$' | cut -d' ' -f 2)
-
-if [ -n "$changed_files" ]; then
- 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
- err=$?
- if [ $err -ne 0 ]; then
- echo "[rt-thread][astyle] we found a obvious fault, please fix the error then commit again"
- exit $err
- else
- echo "[rt-thread][astyle] astyle file ok"
+if which astyle > /dev/null; then
+ if [ -n "$changed_files" ]; then
+ 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
+ err=$?
+ if [ $err -ne 0 ]; then
+ echo "[rt-thread][astyle] we found a obvious fault, please fix the error then commit again"
+ exit $err
+ else
+ echo "[rt-thread][astyle] astyle file ok"
+ fi
fi
+else
+ echo "astyle does not exist"
fi
-
# We only filter the file name with c or cpp file.
changed_files=$(git diff-index --cached $against | \
grep -E '[MA] .*\.(c|cpp|h)$' | cut -d' ' -f 2)
# formatting check
# https://github.com/mysterywolf/formatting
# formatting cmd ref https://github.com/supperthomas/git_auto_script
-if [ -n "$changed_files" ]; then
- formatting $changed_files
- echo "[rt-thread] formatting $changed_files is ok"
- git add $changed_files
- exit 0
+if which formatting > /dev/null; then
+ if [ -n "$changed_files" ]; then
+ formatting $changed_files
+ echo "[rt-thread] formatting $changed_files is ok"
+ git add $changed_files
+ exit 0
+ fi
+else
+ echo "formatting does not exist"
fi
+
exit 0