Skip to content

Commit 924743d

Browse files
committed
Fix submodule fetching from non-default branches with old Git
1 parent ebfa883 commit 924743d

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

cmake/modules/CheckSubmodules.cmake

+6-18
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ ENDFOREACH()
100100

101101
# Once called, status is stored in GIT_RESULT respectively.
102102
# Note: Git likes to write to stderr. Don't assume stderr is error; Check GIT_RESULT instead.
103-
MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE)
103+
MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE NO_DEPTH)
104104
FIND_PACKAGE(Git REQUIRED)
105105
# Handle missing commits
106106
SET(FORCE_REMOTE_FLAG "${FORCE_REMOTE}")
107-
SET(FULL_CLONE_FLAG "${FULL_CLONE}")
107+
SET(NO_DEPTH_FLAG "${NO_DEPTH}")
108108
IF(FORCE_REMOTE_FLAG)
109109
MESSAGE("-- Adding remote submodulefix to ${SUBMODULE_PATH}")
110110
EXECUTE_PROCESS(
@@ -115,7 +115,7 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE)
115115
OUTPUT_QUIET ERROR_QUIET
116116
)
117117
# Recurse
118-
GIT_SUBMODULE(${SUBMODULE_PATH} false false ${FULL_CLONE_FLAG})
118+
GIT_SUBMODULE(${SUBMODULE_PATH} false false ${NO_DEPTH_FLAG})
119119
ELSEIF(${FORCE_DEINIT})
120120
MESSAGE("-- Resetting ${SUBMODULE_PATH}")
121121
EXECUTE_PROCESS(
@@ -125,21 +125,15 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE FULL_CLONE)
125125
)
126126
MESSAGE("-- Deleting ${CMAKE_SOURCE_DIR}/.git/${SUBMODULE_PATH}")
127127
FILE(REMOVE_RECURSE "${CMAKE_SOURCE_DIR}/.git/modules/${SUBMODULE_PATH}")
128-
# Recurse
128+
# Recurse without depth
129129
GIT_SUBMODULE(${SUBMODULE_PATH} false false true)
130130
ELSE()
131131
# Try to use the depth switch
132-
IF(NO_SHALLOW_CLONE OR GIT_VERSION_STRING VERSION_LESS "1.8.4")
132+
IF(NO_SHALLOW_CLONE OR GIT_VERSION_STRING VERSION_LESS "1.8.4" OR NO_DEPTH_FLAG)
133133
# Shallow submodules were introduced in 1.8.4
134134
MESSAGE("-- Fetching ${SUBMODULE_PATH}")
135135
SET(DEPTH_CMD "")
136136
SET(DEPTH_VAL "")
137-
ELSEIF(FULL_CLONE_FLAG)
138-
# Depth doesn't revert easily... It should be "--no-recommend-shallow"
139-
# but it's ignored by nested submodules, use the highest value instead.
140-
MESSAGE("-- Fetching ${SUBMODULE_PATH}")
141-
SET(DEPTH_CMD "--depth")
142-
SET(DEPTH_VAL "2147483647")
143137
ELSE()
144138
MESSAGE("-- Fetching ${SUBMODULE_PATH} @ --depth ${DEPTH_VALUE}")
145139
SET(DEPTH_CMD "--depth")
@@ -201,13 +195,7 @@ FOREACH(_submodule ${SUBMODULE_LIST})
201195
BREAK()
202196
ELSEIF("${GIT_MESSAGE}" MATCHES "${_phrase}")
203197
MESSAGE("-- Retrying ${_submodule} using 'deinit' (attempt ${COUNTED} of ${MAX_ATTEMPTS})...")
204-
IF(COUNTED LESS 2)
205-
SET(FULL_CLONE false)
206-
ELSE()
207-
SET(FULL_CLONE true)
208-
ENDIF()
209-
210-
GIT_SUBMODULE("${_submodule}" true false ${FULL_CLONE})
198+
GIT_SUBMODULE("${_submodule}" true false false)
211199
BREAK()
212200
ENDIF()
213201
ENDFOREACH()

0 commit comments

Comments
 (0)