@@ -45,13 +45,25 @@ const MSYS_USR_VARIANTS: &[&str] = &["mingw64", "mingw32", "clangarm64", "clang6
45
45
///
46
46
/// Currently this is used only for finding the path to an `sh.exe` associated with Git. This is
47
47
/// separate from `installation_config()` and `installation_config_prefix()` in `gix_path::env`.
48
+ /// This is *not* suitable for finding the highest-scoped configuration file, because that could be
49
+ /// installed in an unusual place, or customized via `GIT_CONFIG_SYSTEM` or `GIT_CONFIG_NOSYSTEM`,
50
+ /// all of which `installation_config()` should reflect. Likewise, `installation_config_prefix()`
51
+ /// has strong uses, such as to find a directory inside `ProgramData` containing configuration.
52
+ /// But it is possible that some marginal uses of `installation_config_prefix()`, if they do not
53
+ /// really relate to configuration, could be replaced with `git_for_windows_root()` in the future.
48
54
fn git_for_windows_root ( ) -> Option < & ' static Path > {
49
55
static GIT_ROOT : Lazy < Option < PathBuf > > = Lazy :: new ( || {
50
56
super :: core_dir ( )
51
- . filter ( |core| core. is_absolute ( ) && core. ends_with ( "libexec/git-core" ) )
57
+ . filter ( |core| {
58
+ // Only use this if the directory structure resembles a Git installation. This
59
+ // accepts installations of common types that are not broken when `GIT_EXEC_PATH`
60
+ // is unset, as well as values of `GIT_EXEC_PATH` that are likely to be usable.
61
+ core. is_absolute ( ) && core. ends_with ( "libexec/git-core" )
62
+ } )
52
63
. and_then ( |core| core. ancestors ( ) . nth ( 2 ) )
53
64
. filter ( |prefix| {
54
65
// Only use `libexec/git-core` from inside something `usr`-like, such as `mingw64`.
66
+ // See `MSYS_USR_VARIANTS` for details and the rationale for this restriction.
55
67
MSYS_USR_VARIANTS . iter ( ) . any ( |name| prefix. ends_with ( name) )
56
68
} )
57
69
. and_then ( |prefix| prefix. parent ( ) )
0 commit comments