diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-05-10 15:12:57 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-05-10 17:05:46 +0200 |
commit | 61aa09097f222174ed0dd41254c9a956eb3a8b65 (patch) | |
tree | ee5e1aff77eed4e07991207275dd6d0a5e97b9cf /misc | |
parent | 6e3f47983cabb5f162eaec075d810f717985beda (diff) |
Fix Ubuntu clang-format version detection in the pre-commit hook
Diffstat (limited to 'misc')
-rwxr-xr-x | misc/hooks/pre-commit-clang-format | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/misc/hooks/pre-commit-clang-format b/misc/hooks/pre-commit-clang-format index 7c6e5fcb42..2dac8e9a55 100755 --- a/misc/hooks/pre-commit-clang-format +++ b/misc/hooks/pre-commit-clang-format @@ -99,8 +99,12 @@ if [ ! -x "$CLANG_FORMAT" ] ; then exit 1 fi -CLANG_FORMAT_VERSION="$(clang-format --version | cut -d' ' -f3)" -CLANG_FORMAT_MAJOR="$(echo "$CLANG_FORMAT_VERSION" | cut -d'.' -f1)" +# The returned string can be inconsistent depending on where clang-format comes from. +# Example output strings reported by `clang-format --version`: +# - Ubuntu: "Ubuntu clang-format version 11.0.0-2" +# - Fedora: "clang-format version 11.0.0 (Fedora 11.0.0-2.fc33)" +CLANG_FORMAT_VERSION="$(clang-format --version | sed "s/[^0-9\.]*\([0-9\.]*\).*/\1/")" +CLANG_FORMAT_MAJOR="$(echo "$CLANG_FORMAT_VERSION" | cut -d. -f1)" if [ "$CLANG_FORMAT_MAJOR" != "$RECOMMENDED_CLANG_FORMAT_MAJOR" ]; then echo "Warning: Your clang-format binary is the wrong version ($CLANG_FORMAT_VERSION, expected $RECOMMENDED_CLANG_FORMAT_MAJOR.x.x)." |