Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gix-path/src/env/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ where
}

#[cfg(windows)]
pub(super) static EXE_NAME: &str = "git.exe";
pub(super) const EXE_NAME: &str = "git.exe";
#[cfg(not(windows))]
pub(super) static EXE_NAME: &str = "git";
pub(super) const EXE_NAME: &str = "git";

/// Invoke the git executable to obtain the origin configuration, which is cached and returned.
///
/// The git executable is the one found in PATH or an alternative location.
pub(super) static EXE_INFO: Lazy<Option<BString>> = Lazy::new(exe_info);
pub(super) static GIT_HIGHEST_PRIORITY_CONFIG_PATH: Lazy<Option<BString>> = Lazy::new(exe_info);

#[cfg(windows)]
static NULL_DEVICE: &str = "NUL";
const NULL_DEVICE: &str = "NUL";
#[cfg(not(windows))]
static NULL_DEVICE: &str = "/dev/null";
const NULL_DEVICE: &str = "/dev/null";

fn exe_info() -> Option<BString> {
let mut cmd = git_cmd(EXE_NAME.into());
Expand Down Expand Up @@ -171,7 +171,7 @@ pub(super) fn install_config_path() -> Option<&'static BStr> {
exec_path.push("gitconfig");
return crate::os_string_into_bstring(exec_path.into()).ok();
}
EXE_INFO.clone()
GIT_HIGHEST_PRIORITY_CONFIG_PATH.clone()
});
PATH.as_ref().map(AsRef::as_ref)
}
Expand Down
67 changes: 34 additions & 33 deletions gix-path/src/env/git/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,41 +551,42 @@ mod exe_info {

let maybe_path = exe_info();
assert_eq!(
maybe_path, None,
"Should find no config path if the config would be local even in a `/tmp`-like dir (suppressed system config)"
);
maybe_path, None,
"Should find no config path if the config would be local even in a `/tmp`-like dir (suppressed system config)"
);
}
}

#[test]
fn first_file_from_config_with_origin() {
let macos =
"file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig\0credential.helper\0file:/Users/byron/.gitconfig\0push.default\0";
let win_msys = "file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0";
let win_cmd =
"file:C:/Program Files/Git/etc/gitconfig\0diff.astextplain.textconv\0file:C:/Program Files/Git/etc/gitconfig\0filter.lfs.clean\0";
let win_msys_old =
"file:C:\\ProgramData/Git/config\0diff.astextplain.textconv\0file:C:\\ProgramData/Git/config\0filter.lfs.clean\0";
let linux = "file:/home/parallels/.gitconfig\0core.excludesfile\0";
let bogus = "something unexpected";
let empty = "";

for (source, expected) in [
(
macos,
Some("/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig"),
),
(win_msys, Some("C:/git-sdk-64/etc/gitconfig")),
(win_msys_old, Some("C:\\ProgramData/Git/config")),
(win_cmd, Some("C:/Program Files/Git/etc/gitconfig")),
(linux, Some("/home/parallels/.gitconfig")),
(bogus, None),
(empty, None),
] {
assert_eq!(
super::first_file_from_config_with_origin(source.into()),
expected.map(Into::into)
);
#[test]
fn first_file_from_config_with_origin() {
let macos =
"file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig\0credential.helper\0file:/Users/byron/.gitconfig\0push.default\0";
let win_msys =
"file:C:/git-sdk-64/etc/gitconfig\0core.symlinks\0file:C:/git-sdk-64/etc/gitconfig\0core.autocrlf\0";
let win_cmd =
"file:C:/Program Files/Git/etc/gitconfig\0diff.astextplain.textconv\0file:C:/Program Files/Git/etc/gitconfig\0filter.lfs.clean\0";
let win_msys_old =
"file:C:\\ProgramData/Git/config\0diff.astextplain.textconv\0file:C:\\ProgramData/Git/config\0filter.lfs.clean\0";
let linux = "file:/home/parallels/.gitconfig\0core.excludesfile\0";
let bogus = "something unexpected";
let empty = "";

for (source, expected) in [
(
macos,
Some("/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig"),
),
(win_msys, Some("C:/git-sdk-64/etc/gitconfig")),
(win_msys_old, Some("C:\\ProgramData/Git/config")),
(win_cmd, Some("C:/Program Files/Git/etc/gitconfig")),
(linux, Some("/home/parallels/.gitconfig")),
(bogus, None),
(empty, None),
] {
assert_eq!(
crate::env::git::first_file_from_config_with_origin(source.into()),
expected.map(Into::into)
);
}
}
}

Expand Down