@@ -479,47 +479,19 @@ fn checkout_repo(
479
479
let submodule = match submodule. open ( ) {
480
480
Ok ( submodule) => submodule,
481
481
Err ( _) => {
482
- // git init the submodule in .git/modules/<submodule_path> of the parent repository
483
- let mut init_opts = git2:: RepositoryInitOptions :: new ( ) ;
484
- init_opts. no_reinit ( false ) . no_dotgit_dir ( true ) ;
485
- let workdir = repository
486
- . workdir ( )
487
- . context ( "Could not get parent workdir" ) ?;
488
- init_opts. workdir_path ( & workdir. join ( & submodule_path) ) ;
489
- let gitdir = repository
490
- . path ( )
491
- . join ( Path :: new ( "modules" ) )
492
- . join ( & submodule_path) ;
493
- std:: fs:: create_dir_all ( & gitdir) . context ( "Could not create submodule path" ) ?; // RepositoryInitOptions.mkpath() doesn't seem to work, let's help it
494
- git2:: Repository :: init_opts ( gitdir, & init_opts) . context ( "Could not init submodule" ) ?;
495
-
496
- // update the submodule
482
+ // Init submodule
483
+ submodule
484
+ . repo_init ( true )
485
+ . context ( "Could not initialize submodule repository" ) ?;
486
+
487
+ // Then clone it
497
488
let mut options = git2:: SubmoduleUpdateOptions :: new ( ) ;
498
489
options. fetch ( ssh_agent_fetch_options ( ) ) ;
499
490
options. allow_fetch ( false ) ;
500
- let fetch_result = retry_if_net ( || submodule. update ( true , Some ( & mut options) ) ) ;
501
-
502
- let fetch_result = if let Err ( error) = & fetch_result {
503
- // ignore if the update failed due to missing commit: we'll try fetching it again later
504
- if matches ! ( error. class( ) , git2:: ErrorClass :: Odb )
505
- && matches ! ( error. code( ) , git2:: ErrorCode :: NotFound )
506
- {
507
- Ok ( ( ) )
508
- } else {
509
- fetch_result
510
- }
511
- } else {
512
- fetch_result
513
- } ;
514
-
515
- fetch_result. context ( "Could not update submodule" ) ?;
516
491
517
- // Set the origin remote
518
- retry_if_locked ( || submodule. sync ( ) )
519
- . context ( "Could not sync submodule" )
520
- . unwrap ( ) ;
521
-
522
- submodule. open ( ) . context ( "Could not open submodule" ) ?
492
+ submodule
493
+ . clone ( Some ( & mut options) )
494
+ . context ( "Could not clone submodule" ) ?
523
495
}
524
496
} ;
525
497
@@ -738,7 +710,7 @@ fn ssh_agent_fetch_options() -> git2::FetchOptions<'static> {
738
710
} ) ;
739
711
cbs. certificate_check ( |_cert, _s| {
740
712
tracing:: warn!( %_s, "Ignoring certificate" ) ;
741
- true
713
+ Ok ( git2 :: CertificateCheckStatus :: CertificateOk )
742
714
} ) ;
743
715
let mut fetch_opts = git2:: FetchOptions :: new ( ) ;
744
716
fetch_opts. remote_callbacks ( cbs) ;
0 commit comments