@@ -219,34 +219,41 @@ public static function downloadFile(string $name, string $url, string $filename,
219219 * @throws RuntimeException
220220 * @throws WrongUsageException
221221 */
222- public static function downloadGit (string $ name , string $ url , string $ branch , ?string $ move_path = null , int $ retries = 0 , int $ lock_as = SPC_DOWNLOAD_SOURCE ): void
222+ public static function downloadGit (string $ name , string $ url , string $ branch , ?array $ submodules = null , ? string $ move_path = null , int $ retries = 0 , int $ lock_as = SPC_DOWNLOAD_SOURCE ): void
223223 {
224224 $ download_path = FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ name }" );
225225 if (file_exists ($ download_path )) {
226226 FileSystem::removeDir ($ download_path );
227227 }
228228 logger ()->debug ("cloning {$ name } source " );
229- $ check = !defined ('DEBUG_MODE ' ) ? ' -q ' : '' ;
230- $ cancel_func = function () use ($ download_path ) {
229+
230+ $ quiet = !defined ('DEBUG_MODE ' ) ? '-q --quiet ' : '' ;
231+ $ git = SPC_GIT_EXEC ;
232+ $ shallow = defined ('GIT_SHALLOW_CLONE ' ) ? '--depth 1 --single-branch ' : '' ;
233+ $ recursive = ($ submodules === null ) ? '--recursive ' : '' ;
234+
235+ try {
236+ self ::registerCancelEvent (function () use ($ download_path ) {
237+ if (is_dir ($ download_path )) {
238+ logger ()->warning ('Removing path ' . $ download_path );
239+ FileSystem::removeDir ($ download_path );
240+ }
241+ });
242+ f_passthru ("{$ git } clone {$ quiet } --config core.autocrlf=false --branch \"{$ branch }\" {$ shallow } {$ recursive } \"{$ url }\" \"{$ download_path }\"" );
243+ if ($ submodules !== null ) {
244+ foreach ($ submodules as $ submodule ) {
245+ f_passthru ("cd \"{$ download_path }\" && {$ git } submodule update --init " . escapeshellarg ($ submodule ));
246+ }
247+ }
248+ } catch (RuntimeException $ e ) {
231249 if (is_dir ($ download_path )) {
232- logger ()->warning ('Removing path ' . $ download_path );
233250 FileSystem::removeDir ($ download_path );
234251 }
235- };
236- try {
237- self ::registerCancelEvent ($ cancel_func );
238- f_passthru (
239- SPC_GIT_EXEC . ' clone ' . $ check .
240- (defined ('DEBUG_MODE ' ) ? '' : ' --quiet ' ) .
241- ' --config core.autocrlf=false ' .
242- "--branch \"{$ branch }\" " . (defined ('GIT_SHALLOW_CLONE ' ) ? '--depth 1 --single-branch ' : '' ) . " --recursive \"{$ url }\" \"{$ download_path }\""
243- );
244- } catch (RuntimeException $ e ) {
245252 if ($ e ->getCode () === 2 || $ e ->getCode () === -1073741510 ) {
246253 throw new WrongUsageException ('Keyboard interrupted, download failed ! ' );
247254 }
248255 if ($ retries > 0 ) {
249- self ::downloadGit ($ name , $ url , $ branch , $ move_path , $ retries - 1 );
256+ self ::downloadGit ($ name , $ url , $ branch , $ submodules , $ move_path , $ retries - 1 , $ lock_as );
250257 return ;
251258 }
252259 throw $ e ;
@@ -343,6 +350,7 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f
343350 $ name ,
344351 $ pkg ['url ' ],
345352 $ pkg ['rev ' ],
353+ $ pkg ['submodules ' ] ?? null ,
346354 $ pkg ['extract ' ] ?? null ,
347355 self ::getRetryAttempts (),
348356 SPC_DOWNLOAD_PRE_BUILT
@@ -462,6 +470,7 @@ public static function downloadSource(string $name, ?array $source = null, bool
462470 $ name ,
463471 $ source ['url ' ],
464472 $ source ['rev ' ],
473+ $ source ['submodules ' ] ?? null ,
465474 $ source ['path ' ] ?? null ,
466475 self ::getRetryAttempts (),
467476 $ download_as
0 commit comments