save error on undo commit snapshot

This commit is contained in:
Kiril Videlov 2024-05-30 23:59:30 +02:00
parent 0f482934c8
commit 4b8d97a500
2 changed files with 21 additions and 11 deletions

View File

@ -34,13 +34,16 @@ impl Project {
self.commit_snapshot(snapshot_tree, details)?;
Ok(())
}
pub(crate) fn snapshot_commit_undo(&self, commit_sha: git::Oid) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationKind::UndoCommit).with_trailers(vec![Trailer {
key: "sha".to_string(),
value: commit_sha.to_string(),
}]);
self.create_snapshot(details)?;
pub(crate) fn snapshot_commit_undo(
&self,
snapshot_tree: git::Oid,
result: Result<&(), &Error>,
commit_sha: git::Oid,
) -> anyhow::Result<()> {
let result = result.map(|_| Some(commit_sha.to_string()));
let details = SnapshotDetails::new(OperationKind::UndoCommit)
.with_trailers(result_trailer(result, "sha".to_string()));
self.commit_snapshot(snapshot_tree, details)?;
Ok(())
}
pub(crate) fn snapshot_commit_creation(

View File

@ -725,10 +725,17 @@ impl ControllerInner {
let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository, _| {
let _ = project_repository
.project()
.snapshot_commit_undo(commit_oid);
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into)
let snapshot_tree = project_repository.project().prepare_snapshot();
let result: Result<(), Error> =
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into);
let _ = snapshot_tree.and_then(|snapshot_tree| {
project_repository.project().snapshot_commit_undo(
snapshot_tree,
result.as_ref(),
commit_oid,
)
});
result
})
}