diff options
| -rw-r--r-- | kde-modules/KDEGitCommitHooks.cmake | 5 | ||||
| -rwxr-xr-x | kde-modules/kde-git-commit-hooks/clang-format.sh | 10 | 
2 files changed, 13 insertions, 2 deletions
| diff --git a/kde-modules/KDEGitCommitHooks.cmake b/kde-modules/KDEGitCommitHooks.cmake index c545352d..f9c48ae4 100644 --- a/kde-modules/KDEGitCommitHooks.cmake +++ b/kde-modules/KDEGitCommitHooks.cmake @@ -61,6 +61,11 @@ function(KDE_CONFIGURE_GIT_PRE_COMMIT_HOOK)      )          return()      endif() +    if (COMMAND KDE_CLANG_FORMAT) +        set(HAS_CLANG_FORMAT_COMMAND_INCLUDED TRUE) +    else() +        set(HAS_CLANG_FORMAT_COMMAND_INCLUDED FALSE) +    endif()      set(_write_hook FALSE)      if(KDE_CLANG_FORMAT_EXECUTABLE) diff --git a/kde-modules/kde-git-commit-hooks/clang-format.sh b/kde-modules/kde-git-commit-hooks/clang-format.sh index 3e072768..6b6233eb 100755 --- a/kde-modules/kde-git-commit-hooks/clang-format.sh +++ b/kde-modules/kde-git-commit-hooks/clang-format.sh @@ -5,8 +5,14 @@  readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -v --diff)  if [[ ! -f .clang-format ]]; then -    echo "ERROR: no .clang-format file found in repository root, abort format" -    echo "       run cmake for this repository to generate it" +    if [[ @HAS_CLANG_FORMAT_COMMAND_INCLUDED@ = TRUE ]]; then +        echo "ERROR: no .clang-format file found in repository root, abort format" +        echo "       run cmake for this repository to generate it" +    else +        echo "ERROR: no .clang-format file found in repository root, abort format" +        echo "Make sure the KDEClangFormat CMake module is included, which will copy the KDE .clang-format file during the CMake configuration." +        echo "Alternatively you can manually copy a .clang-format file to the repository root directory." +    fi      exit 1  fi  if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi | 
