diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index c99bcd43562d16..6bd193e06c94ef 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -2033,10 +2033,19 @@ impl LocalWorktree { let abs_new_path = self.absolutize(&new_path); let fs = self.fs.clone(); let copy = cx.background_spawn(async move { + let abs_old_path = abs_old_path?; + let abs_new_path = abs_new_path?; + + if cfg!(target_os = "windows") && abs_new_path.starts_with(&abs_old_path) { + return Err(anyhow::anyhow!( + "{:?} cannot be pasted within its own subfolder", + abs_new_path + )); + } copy_recursive( fs.as_ref(), - &abs_old_path?, - &abs_new_path?, + &abs_old_path, + &abs_new_path, Default::default(), ) .await