Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git-clang-format corresponding to clang-format #6415

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading