diff --git a/.gitattributes b/.gitattributes index 45273c09c9d..e3c944da39b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -45,7 +45,7 @@ zap.pl crlf=input # ghostflow-director GitHub automatic check for maximum repository file size * hooks-max-size=100000 Modules/Numerics/FEM/src/dsrc2c.c hooks-max-size=260000 -Modules/ThirdParty/** hooks-max-size=300000 +Modules/ThirdParty/** hooks-max-size=300000 hooks.style= Modules/ThirdParty/NIFTI/src/nifti/nifti2/nifti2_io.c hooks-max-size=400000 Modules/ThirdParty/VNL/src/vxl/v3p/netlib/triangle.c hooks-max-size=670000 Modules/Filtering/Denoising/include/itkPatchBasedDenoisingImageFilter.hxx hooks-max-size=120000 diff --git a/CMake/ITKModuleClangFormat.cmake b/CMake/ITKModuleClangFormat.cmake index ad5457db6e5..26831151970 100644 --- a/CMake/ITKModuleClangFormat.cmake +++ b/CMake/ITKModuleClangFormat.cmake @@ -10,6 +10,6 @@ option(ITK_USE_CLANG_FORMAT "Enable the use of clang-format for coding style formatting." ${BUILD_TESTING}) mark_as_advanced(ITK_USE_CLANG_FORMAT) -if(BUILD_TESTING AND ITK_USE_CLANG_FORMAT AND NOT CMAKE_CROSSCOMPILING) +if(BUILD_TESTING AND ITK_USE_CLANG_FORMAT AND NOT CMAKE_CROSSCOMPILING AND NOT ITK_FORBID_DOWNLOADS) include(${ITK_CMAKE_DIR}/../Utilities/ClangFormat/DownloadClangFormat.cmake) endif() diff --git a/Utilities/Hooks/pre-commit-style.bash b/Utilities/Hooks/pre-commit-style.bash index 2a8070a8d92..b17009043f8 100644 --- a/Utilities/Hooks/pre-commit-style.bash +++ b/Utilities/Hooks/pre-commit-style.bash @@ -28,18 +28,9 @@ die() { exit 1 } -do_KWStyle=$(git config --bool hooks.KWStyle) || do_KWStyle=false +do_KWStyle=$(git config --bool hooks.KWStyle) || do_KWStyle=true -do_clangformat=$(git config --bool hooks.clangformat) || do_clangformat=false - -if [ "$(uname)" == "Darwin" ]; then - console="/dev/null; then + system_clang_format="$tool" + break + fi + done + clangformat_path=$(git config clangFormat.binary) || + clangformat_path=$(type -p "$system_clang_format" >/dev/null) || + die "clang-format executable was not found. + +Please install clang-format version $clangformat_required_version or set the executable location with -Please install clang-format version 8.0 or set the executable location with + git config clangFormat.binary /path/to/clang-format +" + if ! "$clangformat_path" --version | grep "clang-format version $clangformat_required_version" >/dev/null 2>/dev/null; then + die "clang-format version $clangformat_required_version is required (exactly) - git config hooks.clangformat.path /path/to/clang-format - " +Set the path the clang-format $clangformat_required_version executable with + + git config clangFormat.binary /path/to/clang-format + +or disable the clang-format pre-commit hook with + + git config hooks.clangformat false +" + fi } run_clang_format_check_attr() @@ -188,7 +204,6 @@ run_clangformat_on_file() { # We temporarily change MERGED because the file might already be open, and # the text editor may complain. MERGED="$NEW_MERGED" - cp -- "$BACKUP" "$MERGED" cp -- "$BACKUP" "$LOCAL" run_clang_format_check_attr "$LOCAL" "$REMOTE" "$ERROR_LOG" @@ -196,28 +211,37 @@ run_clangformat_on_file() { if [ $clang_format_status -ne 0 ]; then mv -- "$BACKUP" "$OLD_MERGED" - if test "$merge_keep_temporaries" = "false"; then + if $merge_keep_temporaries; then rm -f -- "$LOCAL" "$REMOTE" "$BACKUP" fi - die "error when running clangformat on $OLD_MERGED" + die "error when running clang-format on $OLD_MERGED" fi + cp -- "$REMOTE" "$MERGED" + + if test $(git hash-object -- "$LOCAL") != $(git hash-object -- "$REMOTE"); then + if [ "$(uname)" == "Darwin" ]; then + run_merge_tool "$merge_tool" "false"