diff options
| -rw-r--r-- | kde-modules/KDEGitCommitHooks.cmake | 35 | 
1 files changed, 19 insertions, 16 deletions
diff --git a/kde-modules/KDEGitCommitHooks.cmake b/kde-modules/KDEGitCommitHooks.cmake index b4819396..bb593080 100644 --- a/kde-modules/KDEGitCommitHooks.cmake +++ b/kde-modules/KDEGitCommitHooks.cmake @@ -55,22 +55,25 @@ function(KDE_CONFIGURE_GIT_PRE_COMMIT_HOOK)      endif()      set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git") -    # In case of tarballs there is no .git directory -    if (IS_DIRECTORY ${GIT_DIR}) -        # The pre-commit hook is a bash script, consequently it won't work on non-unix platforms -        # git on Windows provides its own bash -        if (UNIX OR WIN32) -            if(KDE_CLANG_FORMAT_EXECUTABLE) -                list(FIND ARG_CHECKS "CLANG_FORMAT" _index) -                if (${_index} GREATER -1) -                    set(CLANG_FORMAT_SCRIPT "\"$(git rev-parse --git-common-dir)\"/hooks/scripts/clang-format.sh") -                    configure_file(${CLANG_FORMAT_UNIX} "${GIT_DIR}/hooks/scripts/clang-format.sh" @ONLY) -                endif() -            else() -                message(WARNING "No clang-format executable was found, skipping the formatting pre-commit hook") -            endif() - -            configure_file(${PRE_COMMIT_HOOK_UNIX} "${GIT_DIR}/hooks/pre-commit") +    if (NOT IS_DIRECTORY ${GIT_DIR} # In case of tarballs there is no .git directory +        OR NOT (UNIX OR WIN32) +    ) +        return() +    endif() + +    set(_write_hook FALSE) +    if(KDE_CLANG_FORMAT_EXECUTABLE) +        list(FIND ARG_CHECKS "CLANG_FORMAT" _index) +        if (${_index} GREATER -1) +            set(CLANG_FORMAT_SCRIPT "\"$(git rev-parse --git-common-dir)\"/hooks/scripts/clang-format.sh") +            configure_file(${CLANG_FORMAT_UNIX} "${GIT_DIR}/hooks/scripts/clang-format.sh" @ONLY) +            set(_write_hook TRUE)          endif() +    else() +        message(WARNING "No clang-format executable was found, skipping the formatting pre-commit hook") +    endif() + +    if(_write_hook) +        configure_file(${PRE_COMMIT_HOOK_UNIX} "${GIT_DIR}/hooks/pre-commit")      endif()  endfunction()  | 
