From 9d5fe4bfe201ae4d285d8a0d7db983fbbea3951f Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Sat, 23 Dec 2023 22:15:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=9A=E6=97=A0=E6=84=8F=E9=97=B4?= =?UTF-8?q?=E5=88=A0=E6=8E=89.mit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/restore.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/restore.rs b/src/commands/restore.rs index cc199f3..9d86ea7 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -108,18 +108,22 @@ 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() { + if !util::check_root_dir(path) { 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(); + for sub_path in util::list_subpath(path).unwrap() { + if sub_path.is_dir() + && util::list_files(&sub_path).unwrap().is_empty() + && !util::check_root_dir(&sub_path) + { + fs::remove_dir_all(sub_path).unwrap(); } } } } } + /** 根据filter restore staged */ pub fn restore_index(filter: Option<&Vec>, target_blobs: &Vec<(PathBuf, Hash)>) { let input_paths = preprocess_filters(filter); //预处理filter 将None转化为workdir