From 066d520f1a4cf674e118e3bd6b3685b5f2d5ffa2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 25 Apr 2024 16:27:37 +0200 Subject: [PATCH] less cumbersome error handling for Git errors --- crates/gitbutler-core/src/virtual_branches/errors.rs | 3 +++ .../gitbutler-core/src/virtual_branches/virtual.rs | 12 ++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/gitbutler-core/src/virtual_branches/errors.rs b/crates/gitbutler-core/src/virtual_branches/errors.rs index f802ae893..764e4ff60 100644 --- a/crates/gitbutler-core/src/virtual_branches/errors.rs +++ b/crates/gitbutler-core/src/virtual_branches/errors.rs @@ -55,6 +55,8 @@ pub enum ResetBranchError { DefaultTargetNotSet(DefaultTargetNotSet), #[error(transparent)] Other(#[from] anyhow::Error), + #[error(transparent)] + Git(#[from] git::Error), } impl ErrorWithContext for ResetBranchError { @@ -66,6 +68,7 @@ impl ErrorWithContext for ResetBranchError { error::Context::new(Code::Branches, format!("commit {} not found", oid)) } ResetBranchError::Other(error) => return error.custom_context_or_root_cause().into(), + ResetBranchError::Git(_err) => return None, }) } } diff --git a/crates/gitbutler-core/src/virtual_branches/virtual.rs b/crates/gitbutler-core/src/virtual_branches/virtual.rs index 0caff1d5f..ccf1606a7 100644 --- a/crates/gitbutler-core/src/virtual_branches/virtual.rs +++ b/crates/gitbutler-core/src/virtual_branches/virtual.rs @@ -2056,16 +2056,8 @@ pub fn reset_branch( let repo = &project_repository.git_repository; let diff = trees( repo, - &repo - .find_commit(updated_head) - .map_err(anyhow::Error::from)? - .tree() - .map_err(anyhow::Error::from)?, - &repo - .find_commit(old_head) - .map_err(anyhow::Error::from)? - .tree() - .map_err(anyhow::Error::from)?, + &repo.find_commit(updated_head)?.tree()?, + &repo.find_commit(old_head)?.tree()?, )?; // Assign the new hunks to the branch we're working on.