Reformat Source: Improve version detection
SCRIPTS_DIR=$(dirname "$0")
. "${SCRIPTS_DIR}/include-common"
-CLANG_FORMAT=$(which clang-format-6.0 2> /dev/null)
+CLANG_FORMAT=$(which clang-format-6.0 || which clang-format)
-if [ -z "${CLANG_FORMAT}" ]; then
- CLANG_FORMAT=$(which clang-format)
+if [ -n "${CLANG_FORMAT}" ]; then
+ version=$("${CLANG_FORMAT}" --version 2> /dev/null | sed -E 's/.* ([6-9]+)\.[0-9].[0-9] .*/\1/')
+ [ "$version" -ge 6 ] || unset CLANG_FORMAT
fi
if [ -z "${CLANG_FORMAT}" ]; then
