From 2a16e577beed5cb6d9c8da1ac837f301860f4112 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Sat, 23 Dec 2023 22:16:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=97=A0commit=E6=97=B6=E5=87=BA?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/restore.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/commands/restore.rs b/src/commands/restore.rs index 9d86ea7..2edae55 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -191,8 +191,15 @@ pub fn restore(paths: Vec, source: String, worktree: bool, staged: bool) }; // 分别处理worktree和staged - let tree = Commit::load(&target_commit).get_tree(); - let target_blobs = tree.get_recursive_blobs(); // 相对路径 + let target_blobs = { + if target_commit.is_empty() { + // 没有commit的情况 + Vec::new() + } else { + let tree = Commit::load(&target_commit).get_tree(); + tree.get_recursive_blobs() // 相对路径 + } + }; if worktree { restore_worktree(Some(&paths), &target_blobs); }