From 924743dd1725a542afbeca017a3d22e2558551ed Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Wed, 25 Mar 2020 15:13:37 +0900 Subject: [PATCH] Fix submodule fetching from non-default branches with old Git --- cmake/modules/CheckSubmodules.cmake | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/cmake/modules/CheckSubmodules.cmake b/cmake/modules/CheckSubmodules.cmake index 32a2f995181..f45885cc6fb 100644 --- a/cmake/modules/CheckSubmodules.cmake +++ b/cmake/modules/CheckSubmodules.cmake @@ -100,11 +100,11 @@ ENDFOREACH() # Once called, status is stored in GIT_RESULT respectively. # Note: Git likes to write to stderr. Don't assume stderr is error; Check GIT_RESULT instead. -MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE) +MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE NO_DEPTH) FIND_PACKAGE(Git REQUIRED) # Handle missing commits SET(FORCE_REMOTE_FLAG "${FORCE_REMOTE}") - SET(FULL_CLONE_FLAG "${FULL_CLONE}") + SET(NO_DEPTH_FLAG "${NO_DEPTH}") IF(FORCE_REMOTE_FLAG) MESSAGE("-- Adding remote submodulefix to ${SUBMODULE_PATH}") EXECUTE_PROCESS( @@ -115,7 +115,7 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE) OUTPUT_QUIET ERROR_QUIET ) # Recurse - GIT_SUBMODULE(${SUBMODULE_PATH} false false ${FULL_CLONE_FLAG}) + GIT_SUBMODULE(${SUBMODULE_PATH} false false ${NO_DEPTH_FLAG}) ELSEIF(${FORCE_DEINIT}) MESSAGE("-- Resetting ${SUBMODULE_PATH}") EXECUTE_PROCESS( @@ -125,21 +125,15 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE) ) MESSAGE("-- Deleting ${CMAKE_SOURCE_DIR}/.git/${SUBMODULE_PATH}") FILE(REMOVE_RECURSE "${CMAKE_SOURCE_DIR}/.git/modules/${SUBMODULE_PATH}") - # Recurse + # Recurse without depth GIT_SUBMODULE(${SUBMODULE_PATH} false false true) ELSE() # Try to use the depth switch - IF(NO_SHALLOW_CLONE OR GIT_VERSION_STRING VERSION_LESS "1.8.4") + IF(NO_SHALLOW_CLONE OR GIT_VERSION_STRING VERSION_LESS "1.8.4" OR NO_DEPTH_FLAG) # Shallow submodules were introduced in 1.8.4 MESSAGE("-- Fetching ${SUBMODULE_PATH}") SET(DEPTH_CMD "") SET(DEPTH_VAL "") - ELSEIF(FULL_CLONE_FLAG) - # Depth doesn't revert easily... It should be "--no-recommend-shallow" - # but it's ignored by nested submodules, use the highest value instead. - MESSAGE("-- Fetching ${SUBMODULE_PATH}") - SET(DEPTH_CMD "--depth") - SET(DEPTH_VAL "2147483647") ELSE() MESSAGE("-- Fetching ${SUBMODULE_PATH} @ --depth ${DEPTH_VALUE}") SET(DEPTH_CMD "--depth") @@ -201,13 +195,7 @@ FOREACH(_submodule ${SUBMODULE_LIST}) BREAK() ELSEIF("${GIT_MESSAGE}" MATCHES "${_phrase}") MESSAGE("-- Retrying ${_submodule} using 'deinit' (attempt ${COUNTED} of ${MAX_ATTEMPTS})...") - IF(COUNTED LESS 2) - SET(FULL_CLONE false) - ELSE() - SET(FULL_CLONE true) - ENDIF() - - GIT_SUBMODULE("${_submodule}" true false ${FULL_CLONE}) + GIT_SUBMODULE("${_submodule}" true false false) BREAK() ENDIF() ENDFOREACH()