save error on unapply branch snapshot

This commit is contained in:
Kiril Videlov 2024-05-30 23:44:58 +02:00
parent 618c7adedc
commit 0f482934c8
3 changed files with 31 additions and 19 deletions

View File

@ -15,20 +15,23 @@ impl Project {
pub(crate) fn snapshot_branch_applied(
&self,
snapshot_tree: git::Oid,
result: &Result<String, Error>,
result: Result<&String, &Error>,
) -> anyhow::Result<()> {
let result = result.map(|o| Some(o.clone()));
let details = SnapshotDetails::new(OperationKind::ApplyBranch)
.with_trailers(result_trailer(result, "name".to_string()));
self.commit_snapshot(snapshot_tree, details)?;
Ok(())
}
pub(crate) fn snapshot_branch_unapplied(&self, branch_name: String) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationKind::UnapplyBranch).with_trailers(vec![Trailer {
key: "name".to_string(),
value: branch_name,
}]);
self.create_snapshot(details)?;
pub(crate) fn snapshot_branch_unapplied(
&self,
snapshot_tree: git::Oid,
result: Result<&Option<Branch>, &Error>,
) -> anyhow::Result<()> {
let result = result.map(|o| o.clone().map(|b| b.name));
let details = SnapshotDetails::new(OperationKind::UnapplyBranch)
.with_trailers(result_trailer(result, "name".to_string()));
self.commit_snapshot(snapshot_tree, details)?;
Ok(())
}
pub(crate) fn snapshot_commit_undo(&self, commit_sha: git::Oid) -> anyhow::Result<()> {
@ -156,12 +159,18 @@ impl Project {
}
}
fn result_trailer(result: &Result<String, Error>, key: String) -> Vec<Trailer> {
fn result_trailer(result: Result<Option<String>, &Error>, key: String) -> Vec<Trailer> {
match result {
Ok(v) => vec![Trailer {
key,
value: v.clone(),
}],
Ok(v) => {
if let Some(v) = v {
vec![Trailer {
key,
value: v.clone(),
}]
} else {
vec![]
}
}
Err(error) => vec![Trailer {
key: "error".to_string(),
value: error.to_string(),

View File

@ -638,7 +638,7 @@ impl ControllerInner {
let _ = snapshot_tree.and_then(|snapshot_tree| {
project_repository
.project()
.snapshot_branch_applied(snapshot_tree, &result)
.snapshot_branch_applied(snapshot_tree, result.as_ref())
});
result.map(|_| ())
})
@ -793,8 +793,14 @@ impl ControllerInner {
let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository, _| {
let result = super::unapply_branch(project_repository, branch_id);
result.map(|_| ()).map_err(Into::into)
let snapshot_tree = project_repository.project().prepare_snapshot();
let result = super::unapply_branch(project_repository, branch_id).map_err(Into::into);
let _ = snapshot_tree.and_then(|snapshot_tree| {
project_repository
.project()
.snapshot_branch_unapplied(snapshot_tree, result.as_ref())
});
result.map(|_| ())
})
}

View File

@ -635,9 +635,6 @@ pub fn unapply_branch(
if !target_branch.applied {
return Ok(Some(target_branch));
}
let _ = project_repository
.project()
.snapshot_branch_unapplied(target_branch.name.clone());
let default_target = vb_state.get_default_target()?;
let repo = &project_repository.git_repository;