Skip to content

Commit 8ba04e0

Browse files
committed
fix: always try HOME environment variable first when obtaining the home directory.
This will fix issues like the one described here: stacked-git/stgit#407
1 parent 74704c7 commit 8ba04e0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gix-path/src/env/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,16 @@ pub fn home_dir() -> Option<PathBuf> {
101101
std::env::var("HOME").map(PathBuf::from).ok()
102102
}
103103

104+
/// Tries to obtain the home directory from `HOME` on all platforms, but falls back to [`home::home_dir()`] for
105+
/// more complex ways of obtaining a home directory, particularly useful on Windows.
106+
///
107+
/// The reason `HOME` is tried first is to allow Windows users to have a custom location for their linux-style
108+
/// home, as otherwise they would have to accumulate dot files in a directory these are inconvenient and perceived
109+
/// as clutter.
104110
#[cfg(not(target_family = "wasm"))]
105-
pub use home::home_dir;
111+
pub fn home_dir() -> Option<PathBuf> {
112+
std::env::var_os("HOME").map(Into::into).or_else(home::home_dir)
113+
}
106114

107115
/// Returns the contents of an environment variable of `name` with some special handling
108116
/// for certain environment variables (like `HOME`) for platform compatibility.

0 commit comments

Comments
 (0)