Skip to content

Commit 042efa0

Browse files
committed
fix: on Windows, Source::User now produces a directory even if HOME is not set.
This way it's easier to use downstream which may not have typical environment variables set, particularly on Windows.
1 parent d0bf760 commit 042efa0

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
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/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ serde = { version = "1.0.114", optional = true, default-features = false, featur
3535
smallvec = "1.15.1"
3636
once_cell = "1.21.3"
3737

38+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
39+
home = "0.5.5"
40+
3841
document-features = { version = "0.2.0", optional = true }
3942

4043
[dev-dependencies]

gix-config/src/source.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,22 @@ impl Source {
100100
User => env_var("GIT_CONFIG_GLOBAL")
101101
.map(|global_override| PathBuf::from(global_override).into())
102102
.or_else(|| {
103-
env_var("HOME").map(|home| {
104-
let mut p = PathBuf::from(home);
105-
p.push(".gitconfig");
106-
p.into()
107-
})
103+
env_var("HOME")
104+
.map(PathBuf::from)
105+
.or_else(|| {
106+
#[cfg(not(target_family = "wasm"))]
107+
{
108+
home::home_dir()
109+
}
110+
#[cfg(target_family = "wasm")]
111+
{
112+
None
113+
}
114+
})
115+
.map(|mut p| {
116+
p.push(".gitconfig");
117+
p.into()
118+
})
108119
}),
109120
Local => Some(Path::new("config").into()),
110121
Worktree => Some(Path::new("config.worktree").into()),

0 commit comments

Comments
 (0)