@@ -62,33 +62,28 @@ fn git_for_windows_root() -> Option<&'static Path> {
62
62
63
63
/// Shell path fragments to concatenate to the root of a Git for Windows or MSYS2 installation.
64
64
///
65
- /// These look like absolute Unix-style paths, but the leading `/` separators are present because
66
- /// they simplify forming paths like `C:/Program Files/Git` obtained by removing trailing
67
- /// components from the output of `git --exec-path`.
68
- const RAW_SH_EXE_PATH_SUFFIXES : & [ & str ] = & [
69
- "/bin/sh.exe" , // Usually a shim, which currently we prefer, if available.
70
- "/usr/bin/sh.exe" ,
71
- ] ;
72
-
65
+ /// When appended to the root of a Git for Windows installation, these are locations where `sh.exe`
66
+ /// can usually be found. The leading `/` allow these to be used (only) with `raw_join()`.
73
67
///
68
+ /// These are ordered so that a shim is preferred over a non-shim when they are tried in order.
69
+ const RAW_SH_EXE_PATH_SUFFIXES : & [ & str ] = & [ "/bin/sh.exe" , "/usr/bin/sh.exe" ] ;
70
+
71
+ /// Concatenate a path by appending a raw suffix, which must contain its own leading separator.
74
72
fn raw_join ( path : & Path , raw_suffix : & str ) -> OsString {
75
73
let mut raw_path = OsString :: from ( path) ;
76
74
raw_path. push ( raw_suffix) ;
77
75
raw_path
78
76
}
79
77
80
78
/// Obtain a path to a `sh.exe` on Windows associated with Git, if one can be found.
79
+ ///
80
+ /// The resulting path uses only `/` separators so long as the path obtained from `git --exec-path`
81
+ /// does, which is the case unless it is overridden by setting `GIT_EXEC_PATH` to an unusual value.
81
82
pub ( super ) fn find_sh_on_windows ( ) -> Option < OsString > {
82
- git_for_windows_root ( )
83
- . into_iter ( )
84
- . flat_map ( |git_root| {
85
- // Enumerate locations where `sh.exe` usually is. To avoid breaking scripts that assume the
86
- // shell's own path contains no `\`, and so messages are more readable, append literally
87
- // with `/` separators. The path from `git --exec-path` already uses `/` separators (and no
88
- // trailing `/`) unless explicitly overridden to an unusual value via `GIT_EXEC_PATH`.
89
- RAW_SH_EXE_PATH_SUFFIXES
90
- . iter ( )
91
- . map ( |raw_suffix| raw_join ( git_root, raw_suffix) )
92
- } )
83
+ let git_root = git_for_windows_root ( ) ?;
84
+
85
+ RAW_SH_EXE_PATH_SUFFIXES
86
+ . iter ( )
87
+ . map ( |raw_suffix| raw_join ( git_root, raw_suffix) )
93
88
. find ( |raw_path| Path :: new ( raw_path) . is_file ( ) )
94
89
}
0 commit comments