From c01b947d0bde1663980a15727938ac666ce31f61 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Sun, 7 Jun 2026 19:45:16 +0300 Subject: fix: support windows agent hooks and input paths --- src/worktree.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/worktree.rs') 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, @@ -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") -- cgit v1.2.3