less cumbersome error handling for Git errors

This commit is contained in:
Sebastian Thiel 2024-04-25 16:27:37 +02:00 committed by Mattias Granlund
parent e0c2d82127
commit 066d520f1a
2 changed files with 5 additions and 10 deletions

View File

@ -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,
})
}
}

View File

@ -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.