Skip to content

Commit

Permalink
fix: always try HOME environment variable first when obtaining the …
Browse files Browse the repository at this point in the history
…home directory.

This will fix issues like the one described here:

stacked-git/stgit#407
  • Loading branch information
Byron committed Jan 26, 2024
1 parent 74704c7 commit 8ba04e0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gix-path/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ pub fn home_dir() -> Option<PathBuf> {
std::env::var("HOME").map(PathBuf::from).ok()
}

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

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

0 comments on commit 8ba04e0

Please sign in to comment.