Skip to content

Commit 74cb5ee

Browse files
committed
Merge branch 'utkarshgupta137/main'
2 parents 6ebd61e + 13edfe9 commit 74cb5ee

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-config/tests/file/init/comfort.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn from_git_dir() -> crate::Result {
3030
worktree_dir.join("system.config").display().to_string(),
3131
)
3232
.set("HOME", worktree_dir.display().to_string())
33+
.set("USERPROFILE", worktree_dir.display().to_string())
3334
.set("GIT_CONFIG_COUNT", "1")
3435
.set("GIT_CONFIG_KEY_0", "include.path")
3536
.set(

gix-path/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ bstr = { version = "1.3.0", default-features = false, features = ["std"] }
1717
thiserror = "1.0.26"
1818
once_cell = "1.17.1"
1919

20+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
21+
home = "0.5.4"
22+
2023
[dev-dependencies]
2124
tempfile = "3.3.0"

gix-path/src/env/mod.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,15 @@ pub fn system_prefix() -> Option<&'static Path> {
9797
}
9898
}
9999

100-
/// Returns a platform independent home directory.
101-
///
102-
/// On unix this simply returns $HOME on windows this uses %HOMEDRIVE%\%HOMEPATH% or %USERPROFILE%
100+
/// Returns `$HOME` or `None` if it cannot be found.
101+
#[cfg(target_family = "wasm")]
103102
pub fn home_dir() -> Option<PathBuf> {
104-
if let Some(home) = std::env::var_os("HOME") {
105-
return Some(home.into());
106-
}
107-
108-
// NOTE: technically we should also check HOMESHARE in case HOME is a UNC path
109-
// but git doesn't do this either so probably best to wait for an upstream fix.
110-
#[cfg(windows)]
111-
{
112-
if let Some(homedrive) = std::env::var_os("HOMEDRIVE") {
113-
if let Some(home_path) = std::env::var_os("HOMEPATH") {
114-
let home = PathBuf::from(homedrive).join(home_path);
115-
if home.metadata().map_or(false, |home| home.is_dir()) {
116-
return Some(home);
117-
}
118-
}
119-
}
120-
if let Some(userprofile) = std::env::var_os("USERPROFILE") {
121-
return Some(userprofile.into());
122-
}
123-
}
124-
None
103+
std::env::var("HOME").map(PathBuf::from).ok()
125104
}
126105

106+
#[cfg(not(target_family = "wasm"))]
107+
pub use home::home_dir;
108+
127109
/// Returns the contents of an environment variable of `name` with some special handling
128110
/// for certain environment variables (like `HOME`) for platform compatibility.
129111
pub fn var(name: &str) -> Option<OsString> {

0 commit comments

Comments
 (0)