From a62924f1c492fae3a4d5ebfa4e3cd10ac9c4495c Mon Sep 17 00:00:00 2001 From: yaphet Date: Fri, 19 Apr 2019 14:33:54 +0800 Subject: [PATCH] check .git before create pre-commit hook (#276) --- CMakeLists.txt | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48064c2a37b..c6ab9a1ea3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -310,19 +310,24 @@ add_custom_target( ) -# Create the pre-commit hook every time we run cmake -set(PRE_COMMIT_HOOK ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit) -execute_process( - COMMAND - "rm" "-f" ${PRE_COMMIT_HOOK} -) -execute_process( - COMMAND - "ln" "-s" ${CMAKE_CURRENT_SOURCE_DIR}/cpplint/bin/pre-commit.sh ${PRE_COMMIT_HOOK} - RESULT_VARIABLE retcode -) -IF(${retcode} EQUAL 0) - MESSAGE(STATUS "Creating pre-commit hook done") +IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/") + # Create the pre-commit hook every time we run cmake + message(STATUS "Create the pre-commit hook") + set(PRE_COMMIT_HOOK ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit) + execute_process( + COMMAND + "rm" "-f" ${PRE_COMMIT_HOOK} + ) + execute_process( + COMMAND + "ln" "-s" ${CMAKE_CURRENT_SOURCE_DIR}/cpplint/bin/pre-commit.sh ${PRE_COMMIT_HOOK} + RESULT_VARIABLE retcode + ) + IF(${retcode} EQUAL 0) + MESSAGE(STATUS "Creating pre-commit hook done") + ELSE() + MESSAGE(FATAL_ERROR "Creating pre-commit hook failed: ${retcode}") + ENDIF() ELSE() - MESSAGE(FATAL_ERROR "Creating pre-commit hook failed: ${retcode}") + MESSAGE(FATAL_ERROR "Currently, we don't support downloaded source code.\nPlease using git clone it and rebuild.") ENDIF()