Skip to content

Commit 4d562aa

Browse files
committed
Expand git_for_windows_root() comments
1 parent c322535 commit 4d562aa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gix-path/src/env/auxiliary.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,25 @@ const MSYS_USR_VARIANTS: &[&str] = &["mingw64", "mingw32", "clangarm64", "clang6
4545
///
4646
/// Currently this is used only for finding the path to an `sh.exe` associated with Git. This is
4747
/// 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.
4854
fn git_for_windows_root() -> Option<&'static Path> {
4955
static GIT_ROOT: Lazy<Option<PathBuf>> = Lazy::new(|| {
5056
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+
})
5263
.and_then(|core| core.ancestors().nth(2))
5364
.filter(|prefix| {
5465
// 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.
5567
MSYS_USR_VARIANTS.iter().any(|name| prefix.ends_with(name))
5668
})
5769
.and_then(|prefix| prefix.parent())

0 commit comments

Comments
 (0)