mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 14:31:30 +03:00
Merge pull request #3760 from gitbutlerapp/update-snapshot-commit-creation-impl
update-snapshot-commit-creation-impl
This commit is contained in:
commit
158ed5c15d
@ -133,6 +133,9 @@
|
||||
</div>
|
||||
{:else if ['CreateCommit'].includes(entry.details?.operation || '')}
|
||||
message: {entry.details?.trailers.find((t) => t.key === 'message')?.value}
|
||||
sha: {entry.details?.trailers.find((t) => t.key === 'sha')?.value?.slice(0, 7)}
|
||||
{:else if ['UndoCommit', 'CreateCommit'].includes(entry.details?.operation || '')}
|
||||
sha: {entry.details?.trailers.find((t) => t.key === 'sha')?.value?.slice(0, 7)}
|
||||
{/if}
|
||||
</div>
|
||||
<div>
|
||||
|
@ -15,16 +15,39 @@ pub trait Snapshot {
|
||||
old_branch: Branch,
|
||||
update: BranchUpdateRequest,
|
||||
) -> anyhow::Result<()>;
|
||||
fn snapshot_commit_creation(&self, commit_message: String) -> anyhow::Result<()>;
|
||||
fn snapshot_commit_creation(
|
||||
&self,
|
||||
commit_message: String,
|
||||
sha: Option<String>,
|
||||
) -> anyhow::Result<()>;
|
||||
fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
impl<T: Oplog> Snapshot for T {
|
||||
fn snapshot_commit_creation(&self, commit_message: String) -> anyhow::Result<()> {
|
||||
fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()> {
|
||||
let details =
|
||||
SnapshotDetails::new(OperationType::CreateCommit).with_trailers(vec![Trailer {
|
||||
SnapshotDetails::new(OperationType::UndoCommit).with_trailers(vec![Trailer {
|
||||
key: "sha".to_string(),
|
||||
value: commit_sha,
|
||||
}]);
|
||||
self.create_snapshot(details)?;
|
||||
Ok(())
|
||||
}
|
||||
fn snapshot_commit_creation(
|
||||
&self,
|
||||
commit_message: String,
|
||||
sha: Option<String>,
|
||||
) -> anyhow::Result<()> {
|
||||
let details = SnapshotDetails::new(OperationType::CreateCommit).with_trailers(vec![
|
||||
Trailer {
|
||||
key: "message".to_string(),
|
||||
value: commit_message,
|
||||
}]);
|
||||
},
|
||||
Trailer {
|
||||
key: "sha".to_string(),
|
||||
value: sha.unwrap_or_default(),
|
||||
},
|
||||
]);
|
||||
self.create_snapshot(details)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -483,9 +483,10 @@ impl ControllerInner {
|
||||
)
|
||||
.map_err(Into::into);
|
||||
|
||||
let sha = result.as_ref().ok().map(|oid| oid.to_string());
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.snapshot_commit_creation(message.to_owned());
|
||||
.snapshot_commit_creation(message.to_owned(), sha);
|
||||
result
|
||||
})
|
||||
}
|
||||
@ -812,7 +813,7 @@ impl ControllerInner {
|
||||
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into);
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationType::UndoCommit));
|
||||
.snapshot_commit_undo(commit_oid.to_string());
|
||||
result
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user