From e82b5f8c2935b2c5a50123df0d8883d8542de9a5 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Sat, 23 Dec 2023 21:14:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=A9=BA=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/restore.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/commands/restore.rs b/src/commands/restore.rs index 6fd6e68..cc199f3 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -105,6 +105,20 @@ pub fn restore_worktree(filter: Option<&Vec>, target_blobs: &Vec<(PathB } } } + // 出现在filter中的目录的子目录如果已经是空目录,需要删除 + for path in &input_paths { + if path.is_dir() && util::list_files(path).unwrap().is_empty() { + if path != &util::get_working_dir().unwrap() { + fs::remove_dir_all(path).unwrap(); + } + } else { + for sub_path in util::list_files(path).unwrap() { + if sub_path.is_dir() && util::list_files(&sub_path).unwrap().is_empty() { + fs::remove_dir_all(&sub_path).unwrap(); + } + } + } + } } /** 根据filter restore staged */ pub fn restore_index(filter: Option<&Vec>, target_blobs: &Vec<(PathBuf, Hash)>) {