Initialize missing submodules if a supermodule is present

When fetching dependencies, the submodule directory might not exist
or might be empty. If so, try to initialize the submodule before trying
to add the worktree.

Change-Id: Ie4d6ec483ac9ea3f9207d5ab4cea34d6e0fb2921
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 21fea13125)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer
2020-12-01 17:52:56 +01:00
committed by Qt Cherry-pick Bot
parent de49143621
commit 034a1967a6

View File

@@ -182,6 +182,21 @@ function(qt_internal_get_dependency dependent dependency)
string(SUBSTRING "${git_stdout}" 0 ${index} remote)
message(DEBUG "Will clone from ${remote}")
if(EXISTS "${gitdir}.gitmodules" AND NOT EXISTS "${gitdir}${dependency}/.git")
# super repo exists, but the submodule we need does not - try to initialize
message(NOTICE "Initializing submodule '${dependency}' from ${gitdir}")
execute_process(
COMMAND "git" "submodule" "update" "--init" "${dependency}"
WORKING_DIRECTORY "${gitdir}"
RESULT_VARIABLE git_result
${swallow_output}
)
if (git_result)
# ignore errors, fall back to an independent clone instead
message(WARNING "Failed to initialize submodule '${dependency}' from ${gitdir}")
endif()
endif()
if(EXISTS "${gitdir}${dependency}")
# for the module we want, there seems to be a clone parallel to what we have
message(NOTICE "Adding worktree for ${dependency} from ${gitdir}${dependency}")