@@ -219,34 +219,41 @@ public static function downloadFile(string $name, string $url, string $filename,
219
219
* @throws RuntimeException
220
220
* @throws WrongUsageException
221
221
*/
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
223
223
{
224
224
$ download_path = FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ name }" );
225
225
if (file_exists ($ download_path )) {
226
226
FileSystem::removeDir ($ download_path );
227
227
}
228
228
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 ) {
231
249
if (is_dir ($ download_path )) {
232
- logger ()->warning ('Removing path ' . $ download_path );
233
250
FileSystem::removeDir ($ download_path );
234
251
}
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 ) {
245
252
if ($ e ->getCode () === 2 || $ e ->getCode () === -1073741510 ) {
246
253
throw new WrongUsageException ('Keyboard interrupted, download failed ! ' );
247
254
}
248
255
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 );
250
257
return ;
251
258
}
252
259
throw $ e ;
@@ -343,6 +350,7 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f
343
350
$ name ,
344
351
$ pkg ['url ' ],
345
352
$ pkg ['rev ' ],
353
+ $ pkg ['submodules ' ] ?? null ,
346
354
$ pkg ['extract ' ] ?? null ,
347
355
self ::getRetryAttempts (),
348
356
SPC_DOWNLOAD_PRE_BUILT
@@ -462,6 +470,7 @@ public static function downloadSource(string $name, ?array $source = null, bool
462
470
$ name ,
463
471
$ source ['url ' ],
464
472
$ source ['rev ' ],
473
+ $ source ['submodules ' ] ?? null ,
465
474
$ source ['path ' ] ?? null ,
466
475
self ::getRetryAttempts (),
467
476
$ download_as
0 commit comments