From 043b804c44665b07bd503fdad896bbe0a29311a0 Mon Sep 17 00:00:00 2001 From: Can Celik Date: Thu, 10 Sep 2026 23:33:27 +0300 Subject: feat: route cli commands to saved ssh machines (#3918) --- src/cli/worktree.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/cli/worktree.rs') diff --git a/src/cli/worktree.rs b/src/cli/worktree.rs index 4003eb6a..ba492e97 100644 --- a/src/cli/worktree.rs +++ b/src/cli/worktree.rs @@ -323,6 +323,16 @@ fn print_worktree_help() { } fn normalize_path_arg(value: &str) -> std::io::Result { + if super::target::is_remote() { + if super::target::remote_path_is_absolute(value) || value == "~" || value.starts_with("~/") + { + return Ok(value.to_owned()); + } + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "remote worktree paths must be absolute or start with ~/", + )); + } let path = crate::worktree::expand_tilde_path(value); let absolute = if path.is_absolute() { path @@ -331,3 +341,23 @@ fn normalize_path_arg(value: &str) -> std::io::Result { }; Ok(absolute.display().to_string()) } + +#[cfg(test)] +mod machine_tests { + #[test] + fn remote_worktree_paths_are_not_expanded_on_the_caller_machine() { + crate::cli::target::with_test_client(crate::api::client::ApiClient::local(), || { + for path in [ + "~/Projects/herdr", + "/Users/can/Projects/herdr", + r"C:\work\repo", + "C:/work/repo", + r"\\host\share\repo", + ] { + assert_eq!(super::normalize_path_arg(path).unwrap(), path); + } + assert!(super::normalize_path_arg("../other").is_err()); + assert!(super::normalize_path_arg("C:relative").is_err()); + }); + } +} -- cgit v1.2.3