1717# Module Import
1818# -----------------------------------------------------------------------------
1919import logging
20+ import os
21+ from typing import List
2022
2123from ..command_execution import simple_call_command
2224from ..git_mirror import GitMirror
25+ from ..git_options import GitOptions
2326from .helpers import use_mirror_for_remote_url
2427
2528# -----------------------------------------------------------------------------
3134# -----------------------------------------------------------------------------
3235# Function Definitions
3336# -----------------------------------------------------------------------------
34- def git_clone (git_options ) :
37+ def git_clone (called_as : List [ str ], git_options : GitOptions ) -> int :
3538 """Handle a git clone command.
3639
3740 Args:
41+ called_as (list): The arguments used for the command call.
3842 git_options (obj): The GitOptions object.
3943
4044 Return:
@@ -50,7 +54,24 @@ def git_clone(git_options):
5054 if mirror_path :
5155 if use_mirror_for_remote_url (remote_url ):
5256 mirror = GitMirror (url = remote_url )
53- return mirror .clone_from_mirror (git_options )
57+ retval = mirror .clone_from_mirror (git_options )
58+ if retval == 0 :
59+ if ("--recurse-submodules" in git_options .command_options ) or (
60+ "--recursive" in git_options .command_options
61+ ):
62+ LOG .debug ("Initializing submodules by calling 'git submodule update --init --recursive'." )
63+ if len (git_options .command_args ) > 1 :
64+ target_dir = git_options .command_args [1 ]
65+ else :
66+ target_dir = os .path .basename (mirror .url ).replace (".git" , "" )
67+ command = called_as + git_options .global_options
68+ command += ["-C" , target_dir ]
69+ command += ["submodule" , "update" , "--init" , "--recursive" ]
70+ if "--remote-submodules" in git_options .command_options :
71+ command += ["--remote" ]
72+ retval = simple_call_command (command )
73+
74+ return retval
5475
5576 LOG .debug ("Remote URL does not match the UrlPatterns. Using original git command." )
5677 else :
0 commit comments