Skip to content

Commit

Permalink
Merge pull request #6415 from wthrowe/git-clang-format_version
Browse files Browse the repository at this point in the history
Use git-clang-format corresponding to clang-format
  • Loading branch information
nilsvu authored Jan 14, 2025
2 parents 97c3c28 + 5070cb0 commit 3ecc86a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cmake/FindClangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ if (CLANG_FORMAT_BIN)
string(REGEX REPLACE "clang-format version " ""
CLANG_FORMAT_VERSION ${CLANG_FORMAT_VERSION})
endif()

# Look for a git-clang-format program in the same place as
# clang-format. Versions of git-clang-format are not always
# compatible with other clang-format executables.
get_filename_component(CLANG_FORMAT_DIR ${CLANG_FORMAT_BIN} DIRECTORY)
get_filename_component(CLANG_FORMAT_NAME ${CLANG_FORMAT_BIN} NAME)
find_program(
GIT_CLANG_FORMAT_BIN
NAMES git-${CLANG_FORMAT_NAME}
HINTS ${CLANG_FORMAT_DIR}
NO_DEFAULT_PATH
)
endif()


Expand Down
6 changes: 3 additions & 3 deletions tools/Hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ printf '%s\0' "${commit_files[@]}" | run_checks "${standard_checks[@]}"

###############################################################################
# Use git-clang-format to check for any suspicious formatting of code.
@CLANG_FORMAT_BIN@ --version > /dev/null
@GIT_CLANG_FORMAT_BIN@ --help > /dev/null
if [ $? -eq 0 ]; then
clang_format_diff=$(@GIT_EXECUTABLE@ --no-pager \
clang-format --binary @CLANG_FORMAT_BIN@ --diff --quiet)
clang_format_diff=$(
@GIT_CLANG_FORMAT_BIN@ --binary @CLANG_FORMAT_BIN@ --diff --quiet)
# Clang-format didn't always return the right exit code before version 15,
# so we check the diff output instead (see issue:
# https://github.com/llvm/llvm-project/issues/54758)
Expand Down

0 comments on commit 3ecc86a

Please sign in to comment.