@@ -129,12 +129,26 @@ pub(crate) fn git_command() -> std::process::Command {
129129 }
130130}
131131
132+ pub ( crate ) fn normalise_display_path ( path : & str ) -> String {
133+ #[ cfg( windows) ]
134+ {
135+ if let Some ( stripped) = path. strip_prefix ( r"\\?\" ) {
136+ if let Some ( unc) = stripped. strip_prefix ( r"UNC\" ) {
137+ return format ! ( "\\ \\ {}" , unc) ;
138+ }
139+ return stripped. to_string ( ) ;
140+ }
141+ }
142+ path. to_string ( )
143+ }
144+
132145pub ( crate ) fn set_configured_git_executable_path ( path : String ) {
133146 let trimmed = path. trim ( ) ;
134147 let next = if trimmed. is_empty ( ) {
135148 None
136149 } else {
137- Some ( PathBuf :: from ( trimmed. trim_matches ( '"' ) ) )
150+ let normalised = normalise_display_path ( trimmed. trim_matches ( '"' ) ) ;
151+ Some ( PathBuf :: from ( normalised) )
138152 } ;
139153
140154 if let Ok ( mut configured) = CONFIGURED_GIT_EXE . get_or_init ( || RwLock :: new ( None ) ) . write ( ) {
@@ -165,33 +179,35 @@ fn resolve_on_path(names: &[&str]) -> Option<PathBuf> {
165179}
166180
167181pub ( crate ) fn resolve_active_git_executable_path ( ) -> String {
168- if let Some ( path) = configured_git_executable_path ( ) {
169- return path. to_string_lossy ( ) . into_owned ( ) ;
170- }
171-
172- match git_backend ( ) {
173- GitBackend :: FlatpakHost => "flatpak-spawn --host git" . to_string ( ) ,
174- GitBackend :: FlatpakBundled => "/app/bin/git" . to_string ( ) ,
175- GitBackend :: System => {
176- #[ cfg( windows) ]
177- {
178- let git_exe = PathBuf :: from ( resolve_git_exe ( ) ) ;
179- if git_exe. is_absolute ( ) {
180- return git_exe. to_string_lossy ( ) . into_owned ( ) ;
182+ let raw = if let Some ( path) = configured_git_executable_path ( ) {
183+ path. to_string_lossy ( ) . into_owned ( )
184+ } else {
185+ match git_backend ( ) {
186+ GitBackend :: FlatpakHost => return "flatpak-spawn --host git" . to_string ( ) ,
187+ GitBackend :: FlatpakBundled => return "/app/bin/git" . to_string ( ) ,
188+ GitBackend :: System => {
189+ #[ cfg( windows) ]
190+ {
191+ let git_exe = PathBuf :: from ( resolve_git_exe ( ) ) ;
192+ if git_exe. is_absolute ( ) {
193+ git_exe. to_string_lossy ( ) . into_owned ( )
194+ } else {
195+ resolve_on_path ( & [ "git.exe" , "git" ] )
196+ . map ( |path| path. to_string_lossy ( ) . into_owned ( ) )
197+ . unwrap_or_else ( || "git" . to_string ( ) )
198+ }
181199 }
182- resolve_on_path ( & [ "git.exe" , "git" ] )
183- . map ( |path| path. to_string_lossy ( ) . into_owned ( ) )
184- . unwrap_or_else ( || "git" . to_string ( ) )
185- }
186200
187- #[ cfg( not( windows) ) ]
188- {
189- resolve_on_path ( & [ "git" ] )
190- . map ( |path| path. to_string_lossy ( ) . into_owned ( ) )
191- . unwrap_or_else ( || "git" . to_string ( ) )
201+ #[ cfg( not( windows) ) ]
202+ {
203+ resolve_on_path ( & [ "git" ] )
204+ . map ( |path| path. to_string_lossy ( ) . into_owned ( ) )
205+ . unwrap_or_else ( || "git" . to_string ( ) )
206+ }
192207 }
193208 }
194- }
209+ } ;
210+ normalise_display_path ( & raw)
195211}
196212
197213pub ( crate ) fn git_version_string ( ) -> Result < String , String > {
@@ -203,7 +219,12 @@ pub(crate) fn git_version_string() -> Result<String, String> {
203219 . map_err ( |error| error. to_string ( ) ) ?;
204220
205221 if output. status . success ( ) {
206- let version = String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) ;
222+ let version = String :: from_utf8_lossy ( & output. stdout )
223+ . trim ( )
224+ . strip_prefix ( "git version " )
225+ . unwrap_or ( "" )
226+ . trim ( )
227+ . to_string ( ) ;
207228 if !version. is_empty ( ) {
208229 return Ok ( version) ;
209230 }
@@ -521,19 +542,20 @@ pub(crate) fn configured_git_command() -> std::process::Command {
521542fn resolve_git_exe ( ) -> std:: ffi:: OsString {
522543 #[ cfg( windows) ]
523544 {
545+ for candidate in & [
546+ r"C:\Program Files\Git\cmd\git.exe" ,
547+ r"C:\Program Files\Git\bin\git.exe" ,
548+ r"C:\Program Files (x86)\Git\cmd\git.exe" ,
549+ ] {
550+ if std:: path:: Path :: new ( candidate) . exists ( ) {
551+ return ( * candidate) . into ( ) ;
552+ }
553+ }
524554 let git_in_path = std:: env:: var_os ( "PATH" )
525555 . map ( |p| std:: env:: split_paths ( & p) . any ( |dir| dir. join ( "git.exe" ) . exists ( ) ) )
526556 . unwrap_or ( false ) ;
527- if !git_in_path {
528- for candidate in & [
529- r"C:\Program Files\Git\cmd\git.exe" ,
530- r"C:\Program Files\Git\bin\git.exe" ,
531- r"C:\Program Files (x86)\Git\cmd\git.exe" ,
532- ] {
533- if std:: path:: Path :: new ( candidate) . exists ( ) {
534- return ( * candidate) . into ( ) ;
535- }
536- }
557+ if git_in_path {
558+ return "git" . into ( ) ;
537559 }
538560 if let Some ( candidate) = bundled_git_exe ( ) {
539561 return candidate. into_os_string ( ) ;
0 commit comments