@@ -392,13 +392,13 @@ impl<'a> GitCheckout<'a> {
392
392
///
393
393
/// [^1]: <https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-none>
394
394
fn update_submodules ( & self , cargo_config : & Config ) -> CargoResult < ( ) > {
395
- return update_submodules ( & self . repo , cargo_config, self . remote_url ( ) ) ;
395
+ return update_submodules ( & self . repo , cargo_config, self . remote_url ( ) . as_str ( ) ) ;
396
396
397
397
/// Recusive helper for [`GitCheckout::update_submodules`].
398
398
fn update_submodules (
399
399
repo : & git2:: Repository ,
400
400
cargo_config : & Config ,
401
- parent_remote_url : & Url ,
401
+ parent_remote_url : & str ,
402
402
) -> CargoResult < ( ) > {
403
403
debug ! ( "update submodules for: {:?}" , repo. workdir( ) . unwrap( ) ) ;
404
404
@@ -420,7 +420,7 @@ impl<'a> GitCheckout<'a> {
420
420
parent : & git2:: Repository ,
421
421
child : & mut git2:: Submodule < ' _ > ,
422
422
cargo_config : & Config ,
423
- parent_remote_url : & Url ,
423
+ parent_remote_url : & str ,
424
424
) -> CargoResult < ( ) > {
425
425
child. init ( false ) ?;
426
426
@@ -444,30 +444,15 @@ impl<'a> GitCheckout<'a> {
444
444
// See [`git submodule add`] documentation.
445
445
//
446
446
// [`git submodule add`]: https://git-scm.com/docs/git-submodule
447
- let child_remote_url = if child_url_str. starts_with ( "./" )
448
- || child_url_str. starts_with ( "../" )
449
- {
450
- let mut new_parent_remote_url = parent_remote_url. clone ( ) ;
451
-
452
- let mut new_path = Cow :: from ( parent_remote_url. path ( ) ) ;
453
- if !new_path. ends_with ( '/' ) {
454
- new_path. to_mut ( ) . push ( '/' ) ;
447
+ let child_remote_url = if [ "./" , "../" ] . iter ( ) . any ( |p| child_url_str. starts_with ( p) ) {
448
+ let mut new_remote_url = parent_remote_url. to_string ( ) ;
449
+ if !new_remote_url. ends_with ( '/' ) {
450
+ new_remote_url. push ( '/' ) ;
455
451
}
456
- new_parent_remote_url. set_path ( & new_path) ;
457
-
458
- new_parent_remote_url. join ( child_url_str) . with_context ( || {
459
- format ! (
460
- "failed to parse relative child submodule url `{child_url_str}` \
461
- using parent base url `{new_parent_remote_url}`"
462
- )
463
- } ) ?
452
+ new_remote_url. push_str ( child_url_str) ;
453
+ Cow :: from ( new_remote_url)
464
454
} else {
465
- Url :: parse ( child_url_str) . with_context ( || {
466
- let child_module_name = child. name ( ) . unwrap_or ( "" ) ;
467
- format ! (
468
- "failed to parse url for submodule `{child_module_name}`: `{child_url_str}`"
469
- )
470
- } ) ?
455
+ Cow :: from ( child_url_str)
471
456
} ;
472
457
473
458
// A submodule which is listed in .gitmodules but not actually
@@ -502,20 +487,17 @@ impl<'a> GitCheckout<'a> {
502
487
let reference = GitReference :: Rev ( head. to_string ( ) ) ;
503
488
cargo_config
504
489
. shell ( )
505
- . status ( "Updating" , format ! ( "git submodule `{}`" , child_remote_url ) ) ?;
490
+ . status ( "Updating" , format ! ( "git submodule `{child_remote_url }`" ) ) ?;
506
491
fetch (
507
492
& mut repo,
508
- child_remote_url. as_str ( ) ,
493
+ & child_remote_url,
509
494
& reference,
510
495
cargo_config,
511
496
RemoteKind :: GitDependency ,
512
497
)
513
498
. with_context ( || {
514
- format ! (
515
- "failed to fetch submodule `{}` from {}" ,
516
- child. name( ) . unwrap_or( "" ) ,
517
- child_remote_url
518
- )
499
+ let name = child. name ( ) . unwrap_or ( "" ) ;
500
+ format ! ( "failed to fetch submodule `{name}` from {child_remote_url}" , )
519
501
} ) ?;
520
502
521
503
let obj = repo. find_object ( head, None ) ?;
0 commit comments