Skip to content

Commit

Permalink
Fix Ubuntu clang-format version detection in the pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed May 10, 2021
1 parent 6e3f479 commit 61aa090
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions misc/hooks/pre-commit-clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down

0 comments on commit 61aa090

Please sign in to comment.