11//! Utilities for handling git repositories, mainly around
22//! authentication/cloning.
33
4- use crate :: core:: GitReference ;
5- use crate :: util:: errors:: CargoResult ;
6- use crate :: util:: { network, Config , IntoUrl , MetricsCounter , Progress } ;
4+ use std:: env;
5+ use std:: fmt;
6+ use std:: fs:: canonicalize;
7+ use std:: path:: { Path , PathBuf } ;
8+ use std:: process:: Command ;
9+ use std:: time:: { Duration , Instant } ;
10+
711use anyhow:: { anyhow, Context as _} ;
812use cargo_util:: paths:: normalize_path;
913use cargo_util:: { paths, ProcessBuilder } ;
@@ -12,13 +16,12 @@ use git2::{self, ErrorClass, ObjectType};
1216use log:: { debug, info} ;
1317use serde:: ser;
1418use serde:: Serialize ;
15- use std:: env;
16- use std:: fmt;
17- use std:: path:: { Path , PathBuf } ;
18- use std:: process:: Command ;
19- use std:: time:: { Duration , Instant } ;
2019use url:: { ParseError , Url } ;
2120
21+ use crate :: core:: GitReference ;
22+ use crate :: util:: errors:: CargoResult ;
23+ use crate :: util:: { network, Config , IntoUrl , MetricsCounter , Progress } ;
24+
2225fn serialize_str < T , S > ( t : & T , s : S ) -> Result < S :: Ok , S :: Error >
2326where
2427 T : fmt:: Display ,
@@ -395,12 +398,12 @@ impl<'a> GitCheckout<'a> {
395398 if Path :: new ( child_url. path ( ) ) . is_relative ( ) {
396399 let parent_remote_path = Path :: new ( parent_remote_url. path ( ) ) ;
397400 let child_remote_path = Path :: new ( child_url. path ( ) ) ;
398- let normalized_path_buf =
399- normalize_path ( & parent_remote_path. join ( child_remote_path) ) ;
400- normalized_path_buf
401- . to_str ( )
402- . expect ( "We had a utf-8 url earlier, but now we don't?" )
403- . to_string ( )
401+ let canonical = canonicalize ( normalize_path (
402+ & parent_remote_path. join ( child_remote_path) ,
403+ ) ) ? ;
404+ let mut final_path = parent_remote_url . clone ( ) ;
405+ final_path . set_path ( canonical . to_string_lossy ( ) . as_ref ( ) ) ;
406+ final_path . to_string ( )
404407 } else {
405408 child_url. to_string ( )
406409 }
@@ -414,13 +417,15 @@ impl<'a> GitCheckout<'a> {
414417 Err ( err) => Err ( err)
415418 . with_context ( || format ! ( "Failed to parse child submodule url" ) ) ?,
416419 } ;
420+ let final_path = canonicalize ( Path :: new ( new_parent_remote_url. path ( ) ) ) ?;
421+ new_parent_remote_url. set_path ( final_path. to_string_lossy ( ) . as_ref ( ) ) ;
417422 new_parent_remote_url. to_string ( )
418423 }
419424 Err ( err) => {
420425 return Err ( anyhow:: format_err!(
421426 "Error parsing submodule url: {:?}?" ,
422427 err
423- ) )
428+ ) ) ;
424429 }
425430 } ;
426431
@@ -700,9 +705,9 @@ where
700705 msg. push_str ( "https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli" ) ;
701706 err = err. context ( msg) ;
702707
703- // Otherwise if we didn't even get to the authentication phase them we may
704- // have failed to set up a connection, in these cases hint on the
705- // `net.git-fetch-with-cli` configuration option.
708+ // Otherwise if we didn't even get to the authentication phase them we may
709+ // have failed to set up a connection, in these cases hint on the
710+ // `net.git-fetch-with-cli` configuration option.
706711 } else if let Some ( e) = err. downcast_ref :: < git2:: Error > ( ) {
707712 match e. class ( ) {
708713 ErrorClass :: Net
0 commit comments