diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-07 19:45:16 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-07 19:45:16 +0300 |
| commit | c01b947d0bde1663980a15727938ac666ce31f61 (patch) | |
| tree | 009ad30854d0112f75a0a5ae964b9a6c72ff41ee /src/worktree.rs | |
| parent | 9c101b71d83941ee59d2b68f32f624afd7e2d78e (diff) | |
fix: support windows agent hooks and input paths
Diffstat (limited to 'src/worktree.rs')
| -rw-r--r-- | src/worktree.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/worktree.rs b/src/worktree.rs index 29eb7647..3f8a017f 100644 --- a/src/worktree.rs +++ b/src/worktree.rs @@ -68,13 +68,23 @@ pub(crate) fn expand_tilde_path(path: &str) -> PathBuf { }); if let Some(rest) = tilde_rest { return home_dir_from_env(cfg!(windows), |key| std::env::var_os(key)) - .map(|home| home.join(rest)) + .map(|home| join_tilde_rest(home, rest)) .unwrap_or_else(|_| PathBuf::from(path)); } PathBuf::from(path) } +fn join_tilde_rest(home: PathBuf, rest: &str) -> PathBuf { + if cfg!(windows) { + rest.split(['/', '\\']) + .filter(|component| !component.is_empty()) + .fold(home, |path, component| path.join(component)) + } else { + home.join(rest) + } +} + fn home_dir_from_env( is_windows: bool, env: impl Fn(&str) -> Option<OsString>, @@ -519,11 +529,20 @@ prunable stale #[cfg(windows)] #[test] - fn windows_tilde_expansion_accepts_windows_separator() { + fn windows_tilde_expansion_normalizes_separators() { let old_home = std::env::var_os("HOME"); let old_userprofile = std::env::var_os("USERPROFILE"); std::env::set_var("HOME", "~"); std::env::set_var("USERPROFILE", r"C:\Users\herdr"); + let default_path = expand_tilde_path("~/.herdr/worktrees"); + assert_eq!( + default_path, + PathBuf::from(r"C:\Users\herdr\.herdr\worktrees") + ); + assert_eq!( + default_path.display().to_string(), + r"C:\Users\herdr\.herdr\worktrees" + ); assert_eq!( expand_tilde_path(r"~\.herdr\worktrees"), PathBuf::from(r"C:\Users\herdr\.herdr\worktrees") |
