diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2022-04-10 06:22:49 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2022-04-10 16:31:51 +0200 |
commit | d0f58e8beafe4ffd4bd371152947b84ebe8a8ef2 (patch) | |
tree | 9d2a59740d026e43f3bf133d93dbb75e5bd27b4b | |
parent | abd04935a789bbde7916547a4473f3d201596e95 (diff) | |
download | extra-cmake-modules-d0f58e8beafe4ffd4bd371152947b84ebe8a8ef2.tar.gz extra-cmake-modules-d0f58e8beafe4ffd4bd371152947b84ebe8a8ef2.tar.bz2 |
KDEGitCommitHooks: only configure pre-commit hook if needed
If clang-format isn't found, there is nothing to write to the file.
-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() |